Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
7d2a5e66
Commit
7d2a5e66
authored
Nov 10, 2018
by
fengshuonan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新头像相关的配置
parent
01a6325f
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
233 additions
and
16 deletions
+233
-16
sql/guns.sql
+6
-0
src/main/java/cn/stylefeng/guns/core/interceptor/AttributeSetInteceptor.java
+1
-8
src/main/java/cn/stylefeng/guns/core/util/DefaultImages.java
+2
-3
src/main/java/cn/stylefeng/guns/modular/system/controller/SystemController.java
+47
-3
src/main/java/cn/stylefeng/guns/modular/system/dao/FileInfoMapper.java
+32
-0
src/main/java/cn/stylefeng/guns/modular/system/model/FileInfo.java
+38
-0
src/main/java/cn/stylefeng/guns/modular/system/service/IFileInfoService.java
+39
-0
src/main/java/cn/stylefeng/guns/modular/system/service/impl/FileInfoServiceImpl.java
+67
-0
src/main/resources/application.yml
+1
-2
No files found.
sql/guns.sql
View file @
7d2a5e66
...
@@ -373,6 +373,12 @@ INSERT INTO `sys_user` VALUES ('44', null, 'test', '45abb7879f6a8268f1ef600e6038
...
@@ -373,6 +373,12 @@ INSERT INTO `sys_user` VALUES ('44', null, 'test', '45abb7879f6a8268f1ef600e6038
INSERT
INTO
`sys_user`
VALUES
(
'45'
,
null
,
'boss'
,
'71887a5ad666a18f709e1d4e693d5a35'
,
'1f7bf'
,
'老板'
,
'2017-12-04 00:00:00'
,
'1'
,
''
,
''
,
'1'
,
'24'
,
'1'
,
'2017-12-04 22:24:02'
,
null
);
INSERT
INTO
`sys_user`
VALUES
(
'45'
,
null
,
'boss'
,
'71887a5ad666a18f709e1d4e693d5a35'
,
'1f7bf'
,
'老板'
,
'2017-12-04 00:00:00'
,
'1'
,
''
,
''
,
'1'
,
'24'
,
'1'
,
'2017-12-04 22:24:02'
,
null
);
INSERT
INTO
`sys_user`
VALUES
(
'46'
,
null
,
'manager'
,
'b53cac62e7175637d4beb3b16b2f7915'
,
'j3cs9'
,
'经理'
,
'2017-12-04 00:00:00'
,
'1'
,
''
,
''
,
'1'
,
'24'
,
'1'
,
'2017-12-04 22:24:24'
,
null
);
INSERT
INTO
`sys_user`
VALUES
(
'46'
,
null
,
'manager'
,
'b53cac62e7175637d4beb3b16b2f7915'
,
'j3cs9'
,
'经理'
,
'2017-12-04 00:00:00'
,
'1'
,
''
,
''
,
'1'
,
'24'
,
'1'
,
'2017-12-04 22:24:24'
,
null
);
DROP
TABLE
IF
EXISTS
`sys_file_info`
;
CREATE
TABLE
`sys_file_info`
(
`id`
varchar
(
50
)
NOT
NULL
COMMENT
'主键id'
,
`file_data`
text
COMMENT
'base64编码的文件'
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COMMENT
=
'文件信息表
\n
'
;
DROP
TABLE
IF
EXISTS
`test`
;
DROP
TABLE
IF
EXISTS
`test`
;
CREATE
TABLE
`test`
(
CREATE
TABLE
`test`
(
...
...
src/main/java/cn/stylefeng/guns/core/interceptor/AttributeSetInteceptor.java
View file @
7d2a5e66
...
@@ -18,7 +18,6 @@ package cn.stylefeng.guns.core.interceptor;
...
@@ -18,7 +18,6 @@ package cn.stylefeng.guns.core.interceptor;
import
cn.stylefeng.guns.core.shiro.ShiroKit
;
import
cn.stylefeng.guns.core.shiro.ShiroKit
;
import
cn.stylefeng.guns.core.shiro.ShiroUser
;
import
cn.stylefeng.guns.core.shiro.ShiroUser
;
import
cn.stylefeng.guns.core.util.DefaultImages
;
import
cn.stylefeng.guns.core.util.DefaultImages
;
import
cn.stylefeng.roses.core.util.ToolUtil
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
...
@@ -55,13 +54,7 @@ public class AttributeSetInteceptor extends HandlerInterceptorAdapter {
...
@@ -55,13 +54,7 @@ public class AttributeSetInteceptor extends HandlerInterceptorAdapter {
}
else
{
}
else
{
modelAndView
.
addObject
(
"menus"
,
user
.
getMenus
());
modelAndView
.
addObject
(
"menus"
,
user
.
getMenus
());
modelAndView
.
addObject
(
"name"
,
user
.
getName
());
modelAndView
.
addObject
(
"name"
,
user
.
getName
());
modelAndView
.
addObject
(
"avatar"
,
DefaultImages
.
defaultAvatarUrl
());
if
(
ToolUtil
.
isEmpty
(
user
.
getAvatar
()))
{
modelAndView
.
addObject
(
"avatar"
,
DefaultImages
.
defaultAvatar
());
}
else
{
modelAndView
.
addObject
(
"avatar"
,
user
.
getAvatar
());
}
modelAndView
.
addObject
(
"email"
,
user
.
getEmail
());
modelAndView
.
addObject
(
"email"
,
user
.
getEmail
());
}
}
}
}
...
...
src/main/java/cn/stylefeng/guns/core/util/DefaultImages.java
View file @
7d2a5e66
package
cn
.
stylefeng
.
guns
.
core
.
util
;
package
cn
.
stylefeng
.
guns
.
core
.
util
;
import
cn.stylefeng.guns.core.common.constant.DefaultAvatar
;
import
cn.stylefeng.guns.core.listener.ConfigListener
;
import
cn.stylefeng.guns.core.listener.ConfigListener
;
/**
/**
...
@@ -27,8 +26,8 @@ public class DefaultImages {
...
@@ -27,8 +26,8 @@ public class DefaultImages {
* @author fengshuonan
* @author fengshuonan
* @Date 2018/10/30 5:51 PM
* @Date 2018/10/30 5:51 PM
*/
*/
public
static
String
defaultAvatar
()
{
public
static
String
defaultAvatar
Url
()
{
return
DefaultAvatar
.
BASE_64_AVATAR
;
return
ConfigListener
.
getConf
().
get
(
"contextPath"
)
+
"/system/previewAvatar"
;
}
}
/**
/**
...
...
src/main/java/cn/stylefeng/guns/modular/system/controller/SystemController.java
View file @
7d2a5e66
...
@@ -15,15 +15,20 @@
...
@@ -15,15 +15,20 @@
*/
*/
package
cn
.
stylefeng
.
guns
.
modular
.
system
.
controller
;
package
cn
.
stylefeng
.
guns
.
modular
.
system
.
controller
;
import
cn.hutool.core.codec.Base64
;
import
cn.stylefeng.guns.core.common.constant.DefaultAvatar
;
import
cn.stylefeng.guns.core.shiro.ShiroKit
;
import
cn.stylefeng.guns.core.shiro.ShiroKit
;
import
cn.stylefeng.guns.core.shiro.ShiroUser
;
import
cn.stylefeng.guns.core.shiro.ShiroUser
;
import
cn.stylefeng.guns.modular.system.model.FileInfo
;
import
cn.stylefeng.guns.modular.system.model.User
;
import
cn.stylefeng.guns.modular.system.model.User
;
import
cn.stylefeng.guns.modular.system.service.IFileInfoService
;
import
cn.stylefeng.guns.modular.system.service.IUserService
;
import
cn.stylefeng.guns.modular.system.service.IUserService
;
import
cn.stylefeng.roses.core.base.controller.BaseController
;
import
cn.stylefeng.roses.core.base.controller.BaseController
;
import
cn.stylefeng.roses.core.util.ToolUtil
;
import
cn.stylefeng.roses.core.util.ToolUtil
;
import
cn.stylefeng.roses.kernel.model.exception.RequestEmptyException
;
import
cn.stylefeng.roses.kernel.model.exception.RequestEmptyException
;
import
cn.stylefeng.roses.kernel.model.exception.ServiceException
;
import
cn.stylefeng.roses.kernel.model.exception.ServiceException
;
import
cn.stylefeng.roses.kernel.model.exception.enums.CoreExceptionEnum
;
import
cn.stylefeng.roses.kernel.model.exception.enums.CoreExceptionEnum
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
...
@@ -31,6 +36,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -31,6 +36,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.URLDecoder
;
...
@@ -42,6 +49,7 @@ import java.net.URLDecoder;
...
@@ -42,6 +49,7 @@ import java.net.URLDecoder;
*/
*/
@Controller
@Controller
@RequestMapping
(
"/system"
)
@RequestMapping
(
"/system"
)
@Slf4j
public
class
SystemController
extends
BaseController
{
public
class
SystemController
extends
BaseController
{
private
String
PREFIX
=
"/common/"
;
private
String
PREFIX
=
"/common/"
;
...
@@ -49,6 +57,9 @@ public class SystemController extends BaseController {
...
@@ -49,6 +57,9 @@ public class SystemController extends BaseController {
@Autowired
@Autowired
private
IUserService
userService
;
private
IUserService
userService
;
@Autowired
private
IFileInfoService
fileInfoService
;
/**
/**
* 通用的树列表选择器
* 通用的树列表选择器
*/
*/
...
@@ -86,16 +97,49 @@ public class SystemController extends BaseController {
...
@@ -86,16 +97,49 @@ public class SystemController extends BaseController {
throw
new
RequestEmptyException
(
"请求头像为空"
);
throw
new
RequestEmptyException
(
"请求头像为空"
);
}
}
avatar
=
avatar
.
substring
(
avatar
.
indexOf
(
","
)
+
1
);
fileInfoService
.
uploadAvatar
(
avatar
);
return
SUCCESS_TIP
;
}
/**
* 预览头像
*
* @author fengshuonan
* @Date 2018/11/9 12:45 PM
*/
@RequestMapping
(
"/previewAvatar"
)
@ResponseBody
public
Object
previewAvatar
(
HttpServletResponse
response
)
{
ShiroUser
currentUser
=
ShiroKit
.
getUser
();
ShiroUser
currentUser
=
ShiroKit
.
getUser
();
if
(
currentUser
==
null
)
{
if
(
currentUser
==
null
)
{
throw
new
ServiceException
(
CoreExceptionEnum
.
NO_CURRENT_USER
);
throw
new
ServiceException
(
CoreExceptionEnum
.
NO_CURRENT_USER
);
}
}
User
user
=
userService
.
selectById
(
currentUser
.
getId
());
User
user
=
userService
.
selectById
(
currentUser
.
getId
());
user
.
setAvatar
(
avatar
);
userService
.
updateById
(
user
);
return
SUCCESS_TIP
;
String
avatar
=
user
.
getAvatar
();
if
(
ToolUtil
.
isEmpty
(
avatar
))
{
avatar
=
DefaultAvatar
.
BASE_64_AVATAR
;
}
else
{
FileInfo
fileInfo
=
fileInfoService
.
selectById
(
avatar
);
avatar
=
fileInfo
.
getFileData
();
}
//输出图片的文件流
try
{
response
.
setContentType
(
"image/jpeg"
);
byte
[]
decode
=
Base64
.
decode
(
avatar
);
response
.
getOutputStream
().
write
(
decode
);
}
catch
(
IOException
e
)
{
log
.
error
(
"获取图片的流错误!"
,
avatar
);
throw
new
ServiceException
(
CoreExceptionEnum
.
SERVICE_ERROR
);
}
return
null
;
}
}
}
}
src/main/java/cn/stylefeng/guns/modular/system/dao/FileInfoMapper.java
0 → 100644
View file @
7d2a5e66
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn
.
stylefeng
.
guns
.
modular
.
system
.
dao
;
import
cn.stylefeng.guns.modular.system.model.FileInfo
;
import
com.baomidou.mybatisplus.mapper.BaseMapper
;
/**
* <p>
* 文件信息 Mapper 接口
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
public
interface
FileInfoMapper
extends
BaseMapper
<
FileInfo
>
{
}
\ No newline at end of file
src/main/java/cn/stylefeng/guns/modular/system/model/FileInfo.java
0 → 100644
View file @
7d2a5e66
package
cn
.
stylefeng
.
guns
.
modular
.
system
.
model
;
import
com.baomidou.mybatisplus.activerecord.Model
;
import
com.baomidou.mybatisplus.annotations.TableField
;
import
com.baomidou.mybatisplus.annotations.TableId
;
import
com.baomidou.mybatisplus.annotations.TableName
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* <p>
* 字典表
* </p>
*
* @author stylefeng
* @since 2017-07-11
*/
@TableName
(
"sys_file_info"
)
@Data
public
class
FileInfo
extends
Model
<
FileInfo
>
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 主键id
*/
@TableId
(
value
=
"id"
)
private
String
id
;
@TableField
(
"file_data"
)
private
String
fileData
;
@Override
protected
Serializable
pkVal
()
{
return
id
;
}
}
src/main/java/cn/stylefeng/guns/modular/system/service/IFileInfoService.java
0 → 100644
View file @
7d2a5e66
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn
.
stylefeng
.
guns
.
modular
.
system
.
service
;
import
cn.stylefeng.guns.modular.system.model.FileInfo
;
import
com.baomidou.mybatisplus.service.IService
;
/**
* <p>
* 文件信息 服务类
* </p>
*
* @author stylefeng123
* @since 2018-02-22
*/
public
interface
IFileInfoService
extends
IService
<
FileInfo
>
{
/**
* 上传头像
*
* @author fengshuonan
* @Date 2018/11/10 4:10 PM
*/
void
uploadAvatar
(
String
avatar
);
}
src/main/java/cn/stylefeng/guns/modular/system/service/impl/FileInfoServiceImpl.java
0 → 100644
View file @
7d2a5e66
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
cn
.
stylefeng
.
guns
.
modular
.
system
.
service
.
impl
;
import
cn.stylefeng.guns.core.shiro.ShiroKit
;
import
cn.stylefeng.guns.core.shiro.ShiroUser
;
import
cn.stylefeng.guns.modular.system.dao.FileInfoMapper
;
import
cn.stylefeng.guns.modular.system.model.FileInfo
;
import
cn.stylefeng.guns.modular.system.model.User
;
import
cn.stylefeng.guns.modular.system.service.IFileInfoService
;
import
cn.stylefeng.guns.modular.system.service.IUserService
;
import
cn.stylefeng.roses.kernel.model.exception.ServiceException
;
import
cn.stylefeng.roses.kernel.model.exception.enums.CoreExceptionEnum
;
import
com.baomidou.mybatisplus.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.toolkit.IdWorker
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* <p>
* 文件信息 服务实现类
* </p>
*
* @author stylefeng123
* @since 2018-02-22
*/
@Service
public
class
FileInfoServiceImpl
extends
ServiceImpl
<
FileInfoMapper
,
FileInfo
>
implements
IFileInfoService
{
@Autowired
private
IUserService
userService
;
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
uploadAvatar
(
String
avatar
)
{
ShiroUser
currentUser
=
ShiroKit
.
getUser
();
if
(
currentUser
==
null
)
{
throw
new
ServiceException
(
CoreExceptionEnum
.
NO_CURRENT_USER
);
}
User
user
=
userService
.
selectById
(
currentUser
.
getId
());
//保存文件信息
FileInfo
fileInfo
=
new
FileInfo
();
fileInfo
.
setId
(
IdWorker
.
getIdStr
());
fileInfo
.
setFileData
(
avatar
);
this
.
insert
(
fileInfo
);
//更新用户的头像
user
.
setAvatar
(
fileInfo
.
getId
());
userService
.
updateById
(
user
);
}
}
src/main/resources/application.yml
View file @
7d2a5e66
server
:
server
:
port
:
8080
port
:
8080
tomcat
:
tomcat
:
max-http-header-size
:
10
00
0
#单位:字节
max-http-header-size
:
10
24
0
#单位:字节
guns
:
guns
:
swagger-open
:
true
#是否开启swagger (true/false)
swagger-open
:
true
#是否开启swagger (true/false)
kaptcha-open
:
false
#是否开启登录时验证码 (true/false)
kaptcha-open
:
false
#是否开启登录时验证码 (true/false)
# file-upload-path: d:/tmp #文件上传目录(不配置的话为java.io.tmpdir目录)
spring-session-open
:
false
#是否开启spring session,如果是多机环境需要开启(true/false)
spring-session-open
:
false
#是否开启spring session,如果是多机环境需要开启(true/false)
session-invalidate-time
:
1800
#session失效时间(只在单机环境下生效,多机环境在SpringSessionConfig类中配置) 单位:秒
session-invalidate-time
:
1800
#session失效时间(只在单机环境下生效,多机环境在SpringSessionConfig类中配置) 单位:秒
session-validation-interval
:
900
#多久检测一次失效的session(只在单机环境下生效) 单位:秒
session-validation-interval
:
900
#多久检测一次失效的session(只在单机环境下生效) 单位:秒
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment