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
67296204
Commit
67296204
authored
Apr 25, 2017
by
fsn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增部门管理模块
parent
41b605fd
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
503 additions
and
27 deletions
+503
-27
src/main/java/com/stylefeng/guns/common/exception/BizExceptionEnum.java
+17
-1
src/main/java/com/stylefeng/guns/modular/system/controller/DeptController.java
+98
-0
src/main/java/com/stylefeng/guns/modular/system/dao/DeptDao.java
+4
-0
src/main/java/com/stylefeng/guns/modular/system/dao/mapping/DeptDao.xml
+9
-0
src/main/webapp/WEB-INF/view/system/dept/dept.html
+32
-0
src/main/webapp/WEB-INF/view/system/dept/dept_add.html
+42
-0
src/main/webapp/WEB-INF/view/system/dept/dept_edit.html
+43
-0
src/main/webapp/static/modular/system/dept/dept.js
+109
-0
src/main/webapp/static/modular/system/dept/dept_info.js
+139
-0
src/test/java/com/stylefeng/guns/cache/CacheTest.java
+10
-26
No files found.
src/main/java/com/stylefeng/guns/common/exception/BizExceptionEnum.java
View file @
67296204
...
@@ -7,15 +7,31 @@ package com.stylefeng.guns.common.exception;
...
@@ -7,15 +7,31 @@ package com.stylefeng.guns.common.exception;
*/
*/
public
enum
BizExceptionEnum
{
public
enum
BizExceptionEnum
{
/**
* 文件上传
*/
FILE_READING_ERROR
(
400
,
"FILE_READING_ERROR!"
),
FILE_READING_ERROR
(
400
,
"FILE_READING_ERROR!"
),
FILE_NOT_FOUND
(
400
,
"FILE_NOT_FOUND!"
),
FILE_NOT_FOUND
(
400
,
"FILE_NOT_FOUND!"
),
/**
* 权限和数据问题
*/
DB_RESOURCE_NULL
(
400
,
"数据库中没有该资源"
),
DB_RESOURCE_NULL
(
400
,
"数据库中没有该资源"
),
NO_PERMITION
(
405
,
"无权访问该资源"
),
NO_PERMITION
(
405
,
"无权访问该资源"
),
REQUEST_INVALIDATE
(
400
,
"请求数据格式不正确"
),
/**
* 账户问题
*/
USER_ALREADY_REG
(
401
,
"该用户已经注册"
),
USER_ALREADY_REG
(
401
,
"该用户已经注册"
),
NO_THIS_USER
(
400
,
"没有此用户"
),
NO_THIS_USER
(
400
,
"没有此用户"
),
REQUEST_INVALIDATE
(
400
,
"请求数据格式不正确"
),
USER_NOT_EXISTED
(
400
,
"没有此用户"
),
USER_NOT_EXISTED
(
400
,
"没有此用户"
),
ACCOUNT_FREEZED
(
401
,
"账号被冻结"
),
ACCOUNT_FREEZED
(
401
,
"账号被冻结"
),
/**
* 错误的请求
*/
REQUEST_NULL
(
400
,
"请求为空"
),
REQUEST_NULL
(
400
,
"请求为空"
),
SERVER_ERROR
(
500
,
"服务器异常"
);
SERVER_ERROR
(
500
,
"服务器异常"
);
...
...
src/main/java/com/stylefeng/guns/modular/system/controller/DeptController.java
View file @
67296204
package
com
.
stylefeng
.
guns
.
modular
.
system
.
controller
;
package
com
.
stylefeng
.
guns
.
modular
.
system
.
controller
;
import
com.stylefeng.guns.common.annotion.log.BussinessLog
;
import
com.stylefeng.guns.common.constant.factory.ConstantFactory
;
import
com.stylefeng.guns.common.controller.BaseController
;
import
com.stylefeng.guns.common.controller.BaseController
;
import
com.stylefeng.guns.common.exception.BizExceptionEnum
;
import
com.stylefeng.guns.common.exception.BussinessException
;
import
com.stylefeng.guns.common.node.ZTreeNode
;
import
com.stylefeng.guns.common.node.ZTreeNode
;
import
com.stylefeng.guns.core.log.LogObjectHolder
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
com.stylefeng.guns.modular.system.dao.DeptDao
;
import
com.stylefeng.guns.modular.system.dao.DeptDao
;
import
com.stylefeng.guns.persistence.dao.DeptMapper
;
import
com.stylefeng.guns.persistence.model.Dept
;
import
org.springframework.stereotype.Controller
;
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.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
...
@@ -20,9 +30,42 @@ import java.util.List;
...
@@ -20,9 +30,42 @@ import java.util.List;
@RequestMapping
(
"/dept"
)
@RequestMapping
(
"/dept"
)
public
class
DeptController
extends
BaseController
{
public
class
DeptController
extends
BaseController
{
private
String
PREFIX
=
"/system/dept/"
;
@Resource
@Resource
DeptDao
deptDao
;
DeptDao
deptDao
;
@Resource
DeptMapper
deptMapper
;
/**
* 跳转到部门管理首页
*/
@RequestMapping
(
""
)
public
String
index
()
{
return
PREFIX
+
"dept.html"
;
}
/**
* 跳转到添加部门
*/
@RequestMapping
(
"/dept_add"
)
public
String
deptAdd
()
{
return
PREFIX
+
"dept_add.html"
;
}
/**
* 跳转到修改部门
*/
@RequestMapping
(
"/dept_update/{deptId}"
)
public
String
deptUpdate
(
@PathVariable
Integer
deptId
,
Model
model
)
{
Dept
dept
=
deptMapper
.
selectById
(
deptId
);
model
.
addAttribute
(
dept
);
model
.
addAttribute
(
"pName"
,
ConstantFactory
.
me
().
getDeptName
(
dept
.
getPid
()));
LogObjectHolder
.
me
().
set
(
dept
);
return
PREFIX
+
"dept_edit.html"
;
}
/**
/**
* 获取部门的tree列表
* 获取部门的tree列表
*/
*/
...
@@ -32,4 +75,59 @@ public class DeptController extends BaseController {
...
@@ -32,4 +75,59 @@ public class DeptController extends BaseController {
return
this
.
deptDao
.
tree
();
return
this
.
deptDao
.
tree
();
}
}
/**
* 新增部门
*/
@BussinessLog
(
"添加部门"
)
@RequestMapping
(
value
=
"/add"
)
@ResponseBody
public
Object
add
(
Dept
dept
)
{
if
(
ToolUtil
.
isOneEmpty
(
dept
,
dept
.
getSimplename
()))
{
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
return
this
.
deptMapper
.
insert
(
dept
);
}
/**
* 获取所有部门列表
*/
@RequestMapping
(
value
=
"/list"
)
@ResponseBody
public
Object
list
(
String
condition
)
{
return
this
.
deptDao
.
list
(
condition
);
}
/**
* 部门详情
*/
@RequestMapping
(
value
=
"/detail/{deptId}"
)
@ResponseBody
public
Object
detail
(
@PathVariable
(
"deptId"
)
Integer
deptId
)
{
return
deptMapper
.
selectById
(
deptId
);
}
/**
* 修改部门
*/
@BussinessLog
(
"修改部门"
)
@RequestMapping
(
value
=
"/update"
)
@ResponseBody
public
Object
update
(
Dept
dept
)
{
if
(
ToolUtil
.
isEmpty
(
dept
)
||
dept
.
getId
()
==
null
)
{
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
deptMapper
.
updateById
(
dept
);
return
super
.
SUCCESS_TIP
;
}
/**
* 删除部门
*/
@BussinessLog
(
value
=
"删除部门"
,
key
=
"deptId"
)
@RequestMapping
(
value
=
"/delete/{deptId}"
)
@ResponseBody
public
Object
delete
(
@PathVariable
(
"deptId"
)
Integer
deptId
)
{
deptMapper
.
deleteById
(
deptId
);
return
SUCCESS_TIP
;
}
}
}
src/main/java/com/stylefeng/guns/modular/system/dao/DeptDao.java
View file @
67296204
package
com
.
stylefeng
.
guns
.
modular
.
system
.
dao
;
package
com
.
stylefeng
.
guns
.
modular
.
system
.
dao
;
import
com.stylefeng.guns.common.node.ZTreeNode
;
import
com.stylefeng.guns.common.node.ZTreeNode
;
import
com.stylefeng.guns.persistence.model.Dept
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.List
;
...
@@ -19,4 +21,6 @@ public interface DeptDao {
...
@@ -19,4 +21,6 @@ public interface DeptDao {
* @date 2017年2月17日 下午8:28:43
* @date 2017年2月17日 下午8:28:43
*/
*/
List
<
ZTreeNode
>
tree
();
List
<
ZTreeNode
>
tree
();
List
<
Dept
>
list
(
@Param
(
"condition"
)
String
condition
);
}
}
src/main/java/com/stylefeng/guns/modular/system/dao/mapping/DeptDao.xml
View file @
67296204
...
@@ -14,4 +14,12 @@
...
@@ -14,4 +14,12 @@
) as open from _dept
) as open from _dept
</select>
</select>
<select
id=
"list"
resultType=
"dept"
>
select * from _dept
<if
test=
"condition != null and condition != ''"
>
where simplename like CONCAT('%',#{condition},'%') or fullname like CONCAT('%',#{condition},'%')
</if>
order by num ASC
</select>
</mapper>
</mapper>
\ No newline at end of file
src/main/webapp/WEB-INF/view/system/dept/dept.html
0 → 100644
View file @
67296204
@layout("/common/_container.html"){
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
部门管理
</h5>
</div>
<div
class=
"ibox-content"
>
<div
class=
"row row-lg"
>
<div
class=
"col-sm-12"
>
<div
class=
"row"
>
<div
class=
"col-sm-3"
>
<
#
NameCon
id=
"condition"
name=
"名称"
/>
</div>
<div
class=
"col-sm-3"
>
<
#
button
name=
"搜索"
icon=
"fa-search"
clickFun=
"Dept.search()"
/>
</div>
</div>
<div
class=
"hidden-xs"
id=
"DeptTableToolbar"
role=
"group"
>
<
#
button
name=
"添加"
icon=
"fa-plus"
clickFun=
"Dept.openAddDept()"
/>
<
#
button
name=
"修改"
icon=
"fa-plus"
clickFun=
"Dept.openDeptDetail()"
space=
"true"
/>
<
#
button
name=
"删除"
icon=
"fa-plus"
clickFun=
"Dept.delete()"
space=
"true"
/>
</div>
<
#
table
id=
"DeptTable"
/>
</div>
</div>
</div>
</div>
</div>
</div>
<script
src=
"${ctxPath}/static/modular/system/dept/dept.js"
></script>
@}
src/main/webapp/WEB-INF/view/system/dept/dept_add.html
0 → 100644
View file @
67296204
@layout("/common/_container.html"){
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-content"
>
<div
class=
"form-horizontal"
>
<input
type=
"hidden"
id=
"id"
value=
""
>
<div
class=
"row"
>
<div
class=
"col-sm-6 b-r"
>
<
#
input
id=
"simplename"
name=
"部门名称"
underline=
"true"
/>
<
#
input
id=
"fullname"
name=
"部门全称"
underline=
"true"
/>
<
#
input
id=
"tips"
name=
"备注"
underline=
"true"
/>
</div>
<div
class=
"col-sm-6"
>
<
#
input
id=
"num"
name=
"排序"
underline=
"true"
/>
<
#
input
id=
"pName"
name=
"上级部门"
readonly=
"readonly"
hidden=
"pid"
clickFun=
"DeptInfoDlg.showDeptSelectTree(); return false;"
style=
"background-color: #ffffff !important;"
/>
</div>
</div>
<!-- 父级部门的选择框 -->
<div
id=
"parentDeptMenu"
class=
"menuContent"
style=
"display: none; position: absolute; z-index: 200;"
>
<ul
id=
"parentDeptMenuTree"
class=
"ztree tree-box"
style=
"width: 245px !important;"
></ul>
</div>
<div
class=
"row btn-group-m-t"
>
<div
class=
"col-sm-10"
>
<
#
button
btnCss=
"info"
name=
"提交"
id=
"ensure"
icon=
"fa-check"
clickFun=
"DeptInfoDlg.addSubmit()"
/>
<
#
button
btnCss=
"danger"
name=
"取消"
id=
"cancel"
icon=
"fa-eraser"
clickFun=
"DeptInfoDlg.close()"
/>
</div>
</div>
</div>
</div>
</div>
<script
src=
"${ctxPath}/static/modular/system/dept/dept_info.js"
></script>
@}
src/main/webapp/WEB-INF/view/system/dept/dept_edit.html
0 → 100644
View file @
67296204
@layout("/common/_container.html"){
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-content"
>
<div
class=
"form-horizontal"
>
<input
type=
"hidden"
id=
"id"
value=
"${dept.id}"
>
<div
class=
"row"
>
<div
class=
"col-sm-6 b-r"
>
<
#
input
id=
"simplename"
name=
"部门名称"
underline=
"true"
value=
"${dept.simplename}"
/>
<
#
input
id=
"fullname"
name=
"部门全称"
underline=
"true"
value=
"${dept.fullname}"
/>
<
#
input
id=
"tips"
name=
"备注"
underline=
"true"
value=
"${dept.tips}"
/>
</div>
<div
class=
"col-sm-6"
>
<
#
input
id=
"num"
name=
"排序"
underline=
"true"
value=
"${dept.num}"
/>
<
#
input
id=
"pName"
name=
"上级部门"
readonly=
"readonly"
hidden=
"pid"
hiddenValue=
"${dept.pid}"
value=
"${pName}"
clickFun=
"DeptInfoDlg.showDeptSelectTree(); return false;"
style=
"background-color: #ffffff !important;"
/>
</div>
</div>
<!-- 父级部门的选择框 -->
<div
id=
"parentDeptMenu"
class=
"menuContent"
style=
"display: none; position: absolute; z-index: 200;"
>
<ul
id=
"parentDeptMenuTree"
class=
"ztree tree-box"
style=
"width: 245px !important;"
></ul>
</div>
<div
class=
"row btn-group-m-t"
>
<div
class=
"col-sm-10"
>
<
#
button
btnCss=
"info"
name=
"提交"
id=
"ensure"
icon=
"fa-check"
clickFun=
"DeptInfoDlg.editSubmit()"
/>
<
#
button
btnCss=
"danger"
name=
"取消"
id=
"cancel"
icon=
"fa-eraser"
clickFun=
"DeptInfoDlg.close()"
/>
</div>
</div>
</div>
</div>
</div>
<script
src=
"${ctxPath}/static/modular/system/dept/dept_info.js"
></script>
@}
src/main/webapp/static/modular/system/dept/dept.js
0 → 100644
View file @
67296204
/**
* 部门管理初始化
*/
var
Dept
=
{
id
:
"DeptTable"
,
//表格id
seItem
:
null
,
//选中的条目
table
:
null
,
layerIndex
:
-
1
};
/**
* 初始化表格的列
*/
Dept
.
initColumn
=
function
()
{
return
[
{
field
:
'selectItem'
,
radio
:
true
},
{
title
:
'id'
,
field
:
'id'
,
visible
:
true
,
align
:
'center'
,
valign
:
'middle'
},
{
title
:
'部门简称'
,
field
:
'simplename'
,
align
:
'center'
,
valign
:
'middle'
},
{
title
:
'部门全称'
,
field
:
'fullname'
,
align
:
'center'
,
valign
:
'middle'
},
{
title
:
'排序'
,
field
:
'num'
,
align
:
'center'
,
valign
:
'middle'
},
{
title
:
'备注'
,
field
:
'tips'
,
align
:
'center'
,
valign
:
'middle'
}];
};
/**
* 绑定表格的事件
*/
Dept
.
bindEvent
=
function
()
{
$
(
'#'
+
this
.
id
).
on
(
'click-row.bs.table'
,
function
(
e
,
row
)
{
Dept
.
seItem
=
row
;
});
};
/**
* 检查是否选中
*/
Dept
.
check
=
function
()
{
if
(
this
.
seItem
==
null
)
{
Feng
.
info
(
"请先选中表格中的某一记录!"
);
return
false
;
}
else
{
return
true
;
}
};
/**
* 点击添加部门
*/
Dept
.
openAddDept
=
function
()
{
var
index
=
layer
.
open
({
type
:
2
,
title
:
'添加部门'
,
area
:
[
'800px'
,
'420px'
],
//宽高
fix
:
false
,
//不固定
maxmin
:
true
,
content
:
Feng
.
ctxPath
+
'/dept/dept_add'
});
this
.
layerIndex
=
index
;
};
/**
* 打开查看部门详情
*/
Dept
.
openDeptDetail
=
function
()
{
if
(
this
.
check
())
{
var
index
=
layer
.
open
({
type
:
2
,
title
:
'部门详情'
,
area
:
[
'800px'
,
'420px'
],
//宽高
fix
:
false
,
//不固定
maxmin
:
true
,
content
:
Feng
.
ctxPath
+
'/dept/dept_update/'
+
Dept
.
seItem
.
id
});
this
.
layerIndex
=
index
;
}
};
/**
* 删除部门
*/
Dept
.
delete
=
function
()
{
if
(
this
.
check
())
{
var
ajax
=
new
$ax
(
Feng
.
ctxPath
+
"/dept/delete/"
+
this
.
seItem
.
id
,
function
(
data
)
{
Feng
.
success
(
"删除成功!"
);
Dept
.
table
.
refresh
();
},
function
(
data
)
{
Feng
.
error
(
"删除失败!"
);
});
ajax
.
start
();
}
};
/**
* 查询日志列表
*/
Dept
.
search
=
function
()
{
var
queryData
=
{};
queryData
[
'condition'
]
=
$
(
"#condition"
).
val
();
Dept
.
table
.
refresh
({
query
:
queryData
});
};
$
(
function
()
{
var
defaultColunms
=
Dept
.
initColumn
();
var
table
=
new
BSTable
(
Dept
.
id
,
"/dept/list"
,
defaultColunms
);
table
.
setPaginationType
(
"client"
);
Dept
.
table
=
table
.
init
();
Dept
.
bindEvent
();
});
src/main/webapp/static/modular/system/dept/dept_info.js
0 → 100644
View file @
67296204
/**
* 初始化部门详情对话框
*/
var
DeptInfoDlg
=
{
deptInfoData
:
{}
};
/**
* 清除数据
*/
DeptInfoDlg
.
clearData
=
function
()
{
this
.
deptInfoData
=
{};
}
/**
* 设置对话框中的数据
*
* @param key 数据的名称
* @param val 数据的具体值
*/
DeptInfoDlg
.
set
=
function
(
key
,
val
)
{
this
.
deptInfoData
[
key
]
=
(
typeof
value
==
"undefined"
)
?
$
(
"#"
+
key
).
val
()
:
value
;
return
this
;
}
/**
* 设置对话框中的数据
*
* @param key 数据的名称
* @param val 数据的具体值
*/
DeptInfoDlg
.
get
=
function
(
key
)
{
return
$
(
"#"
+
key
).
val
();
}
/**
* 关闭此对话框
*/
DeptInfoDlg
.
close
=
function
()
{
parent
.
layer
.
close
(
window
.
parent
.
Dept
.
layerIndex
);
}
/**
* 点击部门ztree列表的选项时
*
* @param e
* @param treeId
* @param treeNode
* @returns
*/
DeptInfoDlg
.
onClickDept
=
function
(
e
,
treeId
,
treeNode
)
{
$
(
"#pName"
).
attr
(
"value"
,
instance
.
getSelectedVal
());
$
(
"#pid"
).
attr
(
"value"
,
treeNode
.
id
);
}
/**
* 显示部门选择的树
*
* @returns
*/
DeptInfoDlg
.
showDeptSelectTree
=
function
()
{
var
pName
=
$
(
"#pName"
);
var
pNameOffset
=
$
(
"#pName"
).
offset
();
$
(
"#parentDeptMenu"
).
css
({
left
:
pNameOffset
.
left
+
"px"
,
top
:
pNameOffset
.
top
+
pName
.
outerHeight
()
+
"px"
}).
slideDown
(
"fast"
);
$
(
"body"
).
bind
(
"mousedown"
,
onBodyDown
);
}
/**
* 隐藏部门选择的树
*/
DeptInfoDlg
.
hideDeptSelectTree
=
function
()
{
$
(
"#parentDeptMenu"
).
fadeOut
(
"fast"
);
$
(
"body"
).
unbind
(
"mousedown"
,
onBodyDown
);
// mousedown当鼠标按下就可以触发,不用弹起
}
/**
* 收集数据
*/
DeptInfoDlg
.
collectData
=
function
()
{
this
.
set
(
'id'
).
set
(
'simplename'
).
set
(
'fullname'
).
set
(
'tips'
).
set
(
'num'
).
set
(
'pid'
);
}
/**
* 提交添加部门
*/
DeptInfoDlg
.
addSubmit
=
function
()
{
this
.
clearData
();
this
.
collectData
();
//提交信息
var
ajax
=
new
$ax
(
Feng
.
ctxPath
+
"/dept/add"
,
function
(
data
){
Feng
.
success
(
"添加成功!"
);
window
.
parent
.
Dept
.
table
.
refresh
();
DeptInfoDlg
.
close
();
},
function
(
data
){
Feng
.
error
(
"添加失败!"
+
data
.
responseJSON
.
message
+
"!"
);
});
ajax
.
set
(
this
.
deptInfoData
);
ajax
.
start
();
}
/**
* 提交修改
*/
DeptInfoDlg
.
editSubmit
=
function
()
{
this
.
clearData
();
this
.
collectData
();
//提交信息
var
ajax
=
new
$ax
(
Feng
.
ctxPath
+
"/dept/update"
,
function
(
data
){
Feng
.
success
(
"修改成功!"
);
window
.
parent
.
Dept
.
table
.
refresh
();
DeptInfoDlg
.
close
();
},
function
(
data
){
Feng
.
error
(
"修改失败!"
+
data
.
responseJSON
.
message
+
"!"
);
});
ajax
.
set
(
this
.
deptInfoData
);
ajax
.
start
();
}
function
onBodyDown
(
event
)
{
if
(
!
(
event
.
target
.
id
==
"menuBtn"
||
event
.
target
.
id
==
"parentDeptMenu"
||
$
(
event
.
target
).
parents
(
"#parentDeptMenu"
).
length
>
0
))
{
DeptInfoDlg
.
hideDeptSelectTree
();
}
}
$
(
function
()
{
var
ztree
=
new
$ZTree
(
"parentDeptMenuTree"
,
"/dept/tree"
);
ztree
.
bindOnClick
(
DeptInfoDlg
.
onClickDept
);
ztree
.
init
();
instance
=
ztree
;
});
src/test/java/com/stylefeng/guns/cache/CacheTest.java
View file @
67296204
...
@@ -2,6 +2,7 @@ package com.stylefeng.guns.cache;
...
@@ -2,6 +2,7 @@ package com.stylefeng.guns.cache;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.stylefeng.guns.base.BaseTest
;
import
com.stylefeng.guns.base.BaseTest
;
import
com.stylefeng.guns.common.constant.cache.Cache
;
import
com.stylefeng.guns.common.constant.factory.ConstantFactory
;
import
com.stylefeng.guns.common.constant.factory.ConstantFactory
;
import
com.stylefeng.guns.core.cache.CacheKit
;
import
com.stylefeng.guns.core.cache.CacheKit
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -14,7 +15,7 @@ import java.util.List;
...
@@ -14,7 +15,7 @@ import java.util.List;
* @author fengshuonan
* @author fengshuonan
* @date 2017-04-24 21:00
* @date 2017-04-24 21:00
*/
*/
public
class
CacheTest
extends
BaseTest
{
public
class
CacheTest
extends
BaseTest
{
/**
/**
* 测试没有缓存的情况
* 测试没有缓存的情况
...
@@ -23,38 +24,21 @@ public class CacheTest extends BaseTest{
...
@@ -23,38 +24,21 @@ public class CacheTest extends BaseTest{
* @Date 2017/4/24 21:00
* @Date 2017/4/24 21:00
*/
*/
@Test
@Test
public
void
testNoCache
(){
public
void
testNoCache
()
{
long
beginTIme
=
System
.
currentTimeMillis
();
long
beginTIme
=
System
.
currentTimeMillis
();
//for(int i = 1;i<2000000;i++){
//用缓存200万次查询,速度6秒
String
singleRoleName1
=
ConstantFactory
.
me
().
getDeptName
(
1
);
for
(
int
i
=
1
;
i
<
2000000
;
i
++)
{
String
singleRoleName2
=
ConstantFactory
.
me
().
getDeptName
(
2
);
ConstantFactory
.
me
().
getSingleRoleName
(
1
);
String
singleRoleName3
=
ConstantFactory
.
me
().
getDeptName
(
14
);
}
String
singleRoleName4
=
ConstantFactory
.
me
().
getDeptName
(
15
);
System
.
out
.
println
(
singleRoleName1
);
System
.
out
.
println
(
singleRoleName2
);
System
.
out
.
println
(
singleRoleName3
);
System
.
out
.
println
(
singleRoleName4
);
String
singleRoleName
=
ConstantFactory
.
me
().
getSingleRoleName
(
1
);
System
.
out
.
println
(
singleRoleName
);
//}
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
(
System
.
currentTimeMillis
()
-
beginTIme
);
System
.
out
.
println
(
System
.
currentTimeMillis
()
-
beginTIme
);
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
();
List
constant1
=
CacheKit
.
getKeys
(
"CONSTANT"
);
CacheKit
.
removeAll
(
Cache
.
CONSTANT
);
List
constant1
=
CacheKit
.
getKeys
(
Cache
.
CONSTANT
);
System
.
out
.
println
(
JSON
.
toJSONString
(
constant1
));
System
.
out
.
println
(
JSON
.
toJSONString
(
constant1
));
}
}
}
}
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