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
JeeSpringCloudV3.0
Commits
d5ba54ba
Commit
d5ba54ba
authored
Nov 12, 2018
by
Huang
Browse files
no commit message
parent
da9d3b1b
Changes
399
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
20 of 399+
files are displayed.
Plain diff
Email patch
JeeSpringCloud/src/main/java/com/jeespring/common/service/ServiceException.java
0 → 100644
View file @
d5ba54ba
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.common.service
;
/**
* Service层公用的Exception, 从由Spring管理事务的函数中抛出时会触发事务回滚.
* @author 黄炳桂 516821420@qq.com
*/
public
class
ServiceException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
1L
;
public
ServiceException
(
String
message
)
{
super
(
message
);
}
public
ServiceException
(
Throwable
cause
)
{
super
(
cause
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/service/TreeService.java
0 → 100644
View file @
d5ba54ba
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.common.service
;
import
java.util.List
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.persistence.TreeDao
;
import
com.jeespring.common.persistence.TreeEntity
;
import
com.jeespring.common.utils.Reflections
;
import
com.jeespring.common.utils.StringUtils
;
/**
* Service基类
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Transactional
(
readOnly
=
true
)
public
abstract
class
TreeService
<
D
extends
TreeDao
<
T
>,
T
extends
TreeEntity
<
T
>>
extends
AbstractBaseService
<
D
,
T
>
{
@Override
@Transactional
(
readOnly
=
false
)
public
void
save
(
T
entity
)
{
@SuppressWarnings
(
"unchecked"
)
Class
<
T
>
entityClass
=
Reflections
.
getClassGenricType
(
getClass
(),
1
);
// 如果没有设置父节点,则代表为跟节点,有则获取父节点实体
if
(
entity
.
getParent
()
==
null
||
StringUtils
.
isBlank
(
entity
.
getParentId
())
||
"0"
.
equals
(
entity
.
getParentId
())){
entity
.
setParent
(
null
);
}
else
{
entity
.
setParent
(
super
.
get
(
entity
.
getParentId
()));
}
if
(
entity
.
getParent
()
==
null
){
T
parentEntity
=
null
;
try
{
parentEntity
=
entityClass
.
getConstructor
(
String
.
class
).
newInstance
(
"0"
);
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
e
);
}
entity
.
setParent
(
parentEntity
);
entity
.
getParent
().
setParentIds
(
StringUtils
.
EMPTY
);
}
// 获取修改前的parentIds,用于更新子节点的parentIds
String
oldParentIds
=
entity
.
getParentIds
();
// 设置新的父节点串
entity
.
setParentIds
(
entity
.
getParent
().
getParentIds
()+
entity
.
getParent
().
getId
()+
","
);
// 保存或更新实体
super
.
save
(
entity
);
// 更新子节点 parentIds
T
o
=
null
;
try
{
o
=
entityClass
.
newInstance
();
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
e
);
}
o
.
setParentIds
(
"%,"
+
entity
.
getId
()+
",%"
);
List
<
T
>
list
=
dao
.
findByParentIdsLike
(
o
);
for
(
T
e
:
list
){
if
(
e
.
getParentIds
()
!=
null
&&
oldParentIds
!=
null
){
e
.
setParentIds
(
e
.
getParentIds
().
replace
(
oldParentIds
,
entity
.
getParentIds
()));
preUpdateChild
(
entity
,
e
);
dao
.
updateParentIds
(
e
);
}
}
}
/**
* 预留接口,用户更新子节前调用
* @param childEntity
*/
protected
void
preUpdateChild
(
T
entity
,
T
childEntity
)
{
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/servlet/CKFinderConnectorServlet.java
0 → 100644
View file @
d5ba54ba
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.common.servlet
;
import
java.io.IOException
;
import
javax.servlet.ServletException
;
import
javax.servlet.annotation.WebInitParam
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.ckfinder.connector.ConnectorServlet
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.utils.FileUtils
;
import
com.jeespring.modules.sys.security.SystemAuthorizingRealm.Principal
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* CKFinderConnectorServlet
* @author 黄炳桂 516821420@qq.com
* @version 2014-06-25
*/
@WebServlet
(
urlPatterns
=
"/static/ckfinder/core/connector/java/connector.java"
,
initParams
=
{
@WebInitParam
(
name
=
"XMLConfig"
,
value
=
"classpath:ckfinder.xml"
),
@WebInitParam
(
name
=
"debug"
,
value
=
"false"
),
@WebInitParam
(
name
=
"configuration"
,
value
=
"com.jeespring.common.web.CKFinderConfig"
)
},
loadOnStartup
=
1
)
public
class
CKFinderConnectorServlet
extends
ConnectorServlet
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
prepareGetResponse
(
request
,
response
,
false
);
super
.
doGet
(
request
,
response
);
}
@Override
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
prepareGetResponse
(
request
,
response
,
true
);
super
.
doPost
(
request
,
response
);
}
private
void
prepareGetResponse
(
final
HttpServletRequest
request
,
final
HttpServletResponse
response
,
final
boolean
post
)
throws
ServletException
{
Principal
principal
=
UserUtils
.
getPrincipal
();
if
(
principal
==
null
)
{
return
;
}
String
command
=
request
.
getParameter
(
"command"
);
String
type
=
request
.
getParameter
(
"type"
);
// 初始化时,如果startupPath文件夹不存在,则自动创建startupPath文件夹
if
(
"Init"
.
equals
(
command
))
{
String
startupPath
=
request
.
getParameter
(
"startupPath"
);
// 当前文件夹可指定为模块名
if
(
startupPath
!=
null
)
{
String
[]
ss
=
startupPath
.
split
(
":"
);
if
(
ss
.
length
==
2
)
{
String
realPath
=
Global
.
getUserfilesBaseDir
()
+
Global
.
USERFILES_BASE_URL
+
principal
+
"/"
+
ss
[
0
]
+
ss
[
1
];
FileUtils
.
createDirectory
(
FileUtils
.
path
(
realPath
));
}
}
}
// 快捷上传,自动创建当前文件夹,并上传到该路径
else
if
(
"QuickUpload"
.
equals
(
command
)
&&
type
!=
null
)
{
String
currentFolder
=
request
.
getParameter
(
"currentFolder"
);
// 当前文件夹可指定为模块名
String
realPath
=
Global
.
getUserfilesBaseDir
()
+
Global
.
USERFILES_BASE_URL
+
principal
+
"/"
+
type
+
(
currentFolder
!=
null
?
currentFolder
:
""
);
FileUtils
.
createDirectory
(
FileUtils
.
path
(
realPath
));
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/servlet/UserfilesDownloadServlet.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.servlet
;
import
com.jeespring.common.config.Global
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.web.util.UriUtils
;
import
javax.servlet.ServletException
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
/**
* 查看CK上传的图片
*
* @author 黄炳桂 516821420@qq.com
* @version 2014-06-25
*/
@WebServlet
(
urlPatterns
=
"/userfiles/*"
)
public
class
UserfilesDownloadServlet
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
private
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
public
void
fileOutputStream
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
String
filepath
=
req
.
getRequestURI
();
int
index
=
filepath
.
indexOf
(
Global
.
USERFILES_BASE_URL
);
if
(
index
>=
0
)
{
filepath
=
filepath
.
substring
(
index
+
Global
.
USERFILES_BASE_URL
.
length
());
}
try
{
filepath
=
UriUtils
.
decode
(
filepath
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e1
)
{
logger
.
error
(
String
.
format
(
"解释文件路径失败,URL地址为%s"
,
filepath
),
e1
);
}
File
file
=
new
File
(
Global
.
getUserfilesBaseDir
()
+
Global
.
USERFILES_BASE_URL
+
filepath
);
try
{
FileCopyUtils
.
copy
(
new
FileInputStream
(
file
),
resp
.
getOutputStream
());
resp
.
setHeader
(
"Content-Type"
,
"application/octet-stream"
);
return
;
}
catch
(
FileNotFoundException
e
)
{
req
.
setAttribute
(
"exception"
,
new
FileNotFoundException
(
"请求的文件不存在"
));
req
.
getRequestDispatcher
(
"/webapp/WEB-INF/views/error/404.jsp"
).
forward
(
req
,
resp
);
}
}
@Override
protected
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
fileOutputStream
(
req
,
resp
);
}
@Override
protected
void
doPost
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
fileOutputStream
(
req
,
resp
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/servlet/ValidateCodeServlet.java
0 → 100644
View file @
d5ba54ba
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.common.servlet
;
import
java.awt.Color
;
import
java.awt.Font
;
import
java.awt.Graphics
;
import
java.awt.image.BufferedImage
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Random
;
import
javax.imageio.ImageIO
;
import
javax.servlet.ServletException
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.commons.lang3.StringUtils
;
/**
* 生成随机验证码
* @author 黄炳桂 516821420@qq.com
* @version 2014-7-27
*/
@SuppressWarnings
(
"serial"
)
@WebServlet
(
urlPatterns
=
"/servlet/validateCodeServlet"
)
public
class
ValidateCodeServlet
extends
HttpServlet
{
public
static
final
String
VALIDATE_CODE
=
"validateCode"
;
//private int w = 70;
//private int h = 26;
private
int
w
=
80
;
private
int
h
=
40
;
public
ValidateCodeServlet
()
{
super
();
}
@Override
public
void
destroy
()
{
super
.
destroy
();
}
public
static
boolean
validate
(
HttpServletRequest
request
,
String
validateCode
){
String
code
=
(
String
)
request
.
getSession
().
getAttribute
(
VALIDATE_CODE
);
return
validateCode
.
toUpperCase
().
equals
(
code
);
}
@Override
public
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
String
validateCode
=
request
.
getParameter
(
VALIDATE_CODE
);
// AJAX验证,成功返回true
if
(
StringUtils
.
isNotBlank
(
validateCode
)){
response
.
getOutputStream
().
print
(
validate
(
request
,
validateCode
)?
"true"
:
"false"
);
}
else
{
this
.
doPost
(
request
,
response
);
}
}
@Override
public
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
createImage
(
request
,
response
);
}
private
void
createImage
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setHeader
(
"Pragma"
,
"no-cache"
);
response
.
setHeader
(
"Cache-Control"
,
"no-cache"
);
response
.
setDateHeader
(
"Expires"
,
0
);
response
.
setContentType
(
"image/jpeg"
);
/*
* 得到参数高,宽,都为数字时,则使用设置高宽,否则使用默认值
*/
String
width
=
request
.
getParameter
(
"width"
);
String
height
=
request
.
getParameter
(
"height"
);
if
(
StringUtils
.
isNumeric
(
width
)
&&
StringUtils
.
isNumeric
(
height
))
{
w
=
NumberUtils
.
toInt
(
width
);
h
=
NumberUtils
.
toInt
(
height
);
}
BufferedImage
image
=
new
BufferedImage
(
w
,
h
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics
g
=
image
.
getGraphics
();
/*
* 生成背景
*/
createBackground
(
g
);
/*
* 生成字符
*/
String
s
=
createCharacter
(
g
);
createLine
(
g
);
request
.
getSession
().
setAttribute
(
VALIDATE_CODE
,
s
);
g
.
dispose
();
OutputStream
out
=
response
.
getOutputStream
();
ImageIO
.
write
(
image
,
"JPEG"
,
out
);
out
.
close
();
}
private
Color
getRandColor
(
int
fc
,
int
bc
)
{
int
f
=
fc
;
int
b
=
bc
;
Random
random
=
new
Random
();
if
(
f
>
255
)
{
f
=
255
;
}
if
(
b
>
255
)
{
b
=
255
;
}
return
new
Color
(
f
+
random
.
nextInt
(
b
-
f
),
f
+
random
.
nextInt
(
b
-
f
),
f
+
random
.
nextInt
(
b
-
f
));
}
private
void
createBackground
(
Graphics
g
)
{
// 填充背景
//g.setColor(getRandColor(220,250));
g
.
setColor
(
new
Color
(
255
,
255
,
255
));
g
.
fillRect
(
0
,
0
,
w
,
h
);
// 加入干扰线条
//干扰线条先注释
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
/*g.setColor(getRandColor(40,150));
Random random = new Random();
int x = random.nextInt(w);
int y = random.nextInt(h);
int x1 = random.nextInt(w);
int y1 = random.nextInt(h);
g.drawLine(x, y, x1, y1);*/
}
}
private
void
createLine
(
Graphics
g
)
{
// 加入干扰线条
//干扰线条先注释
Random
randomTimes
=
new
Random
();
int
times
=
randomTimes
.
nextInt
(
25
);
for
(
int
i
=
0
;
i
<
times
;
i
++)
{
//g.setColor(getRandColor(40,150));
g
.
setColor
(
new
Color
(
255
,
255
,
255
));
Random
random
=
new
Random
();
int
x
=
random
.
nextInt
(
w
);
int
y
=
random
.
nextInt
(
h
);
int
x1
=
random
.
nextInt
(
w
);
int
y1
=
random
.
nextInt
(
h
);
g
.
drawLine
(
x
,
y
,
x1
,
y1
);
}
}
private
String
createCharacter
(
Graphics
g
)
{
/*char[] codeSeq = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' };*/
char
[]
codeSeq
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
};
//String[] fontTypes = {"Arial","Arial Black","AvantGarde Bk BT","Calibri"};
String
[]
fontTypes
=
{
"Ravie"
,
"Antique Olive Compact"
,
"Fixedsys"
,
"Wide Latin"
,
"Gill Sans Ultra Bold"
};
Random
random
=
new
Random
();
StringBuilder
s
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
String
r
=
String
.
valueOf
(
codeSeq
[
random
.
nextInt
(
codeSeq
.
length
)]);
//random.nextInt(10));
//g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100)));
g
.
setColor
(
new
Color
(
70
,
70
,
70
));
//g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)],Font.BOLD,26));
g
.
setFont
(
new
Font
(
"Arial"
,
Font
.
ITALIC
,
18
));
//g.drawString(r, 15 * i + 5, 19 + random.nextInt(8));
g
.
drawString
(
r
,
20
*
i
+
4
,
26
);
s
.
append
(
r
);
}
return
s
.
toString
();
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/sms/SMSUtils.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.sms
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
com.jeespring.common.security.Digests
;
/*
功能: 企信通PHP HTTP接口 发送短信
修改日期: 2014-03-19
说明: http://api.cnsms.cn/?ac=send&uid=用户账号&pwd=MD5位32密码&mobile=号码&content=内容
状态:
100 发送成功
101 验证失败
102 短信不足
103 操作失败
104 非法字符
105 内容过多
106 号码过多
107 频率过快
108 号码内容空
109 账号冻结
110 禁止频繁单条发送
111 系统暂定发送
112 号码不正确
120 系统升级
*/
public
class
SMSUtils
{
//发送短信,uid,pwd,参数值请向企信通申请, tel:发送的手机号, content:发送的内容
public
static
String
send
(
String
uid
,
String
pwd
,
String
tel
,
String
content
)
throws
IOException
{
try
{
// 创建StringBuffer对象用来操作字符串
StringBuffer
sb
=
new
StringBuffer
(
"http://api.cnsms.cn/?"
);
// 向StringBuffer追加用户名
sb
.
append
(
"ac=send&uid="
+
uid
);
//在此申请企信通uid,并进行配置用户名
// 向StringBuffer追加密码(密码采用MD5 32位 小写)
sb
.
append
(
"&encode=utf8"
);
// 向StringBuffer追加密码(密码采用MD5 32位 小写)
sb
.
append
(
"&pwd="
+
Digests
.
string2MD5
(
pwd
));
//在此申请企信通uid,并进行配置密码
// 向StringBuffer追加手机号码
sb
.
append
(
"&mobile="
+
tel
);
// 向StringBuffer追加消息内容转URL标准码
sb
.
append
(
"&content="
+
URLEncoder
.
encode
(
content
,
"utf8"
));
// 创建url对象
URL
url
=
new
URL
(
sb
.
toString
());
// 打开url连接
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
// 设置url请求方式 ‘get’ 或者 ‘post’
connection
.
setRequestMethod
(
"POST"
);
// 发送
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
url
.
openStream
()));
// 返回发送结果
String
inputline
=
in
.
readLine
();
return
inputline
;
}
catch
(
Exception
e
){
return
""
;
}
}
public
static
String
sendPass
(
String
tel
,
String
password
)
throws
IOException
{
//发送内容
String
content
=
"您的新密码是:"
+
password
+
",请登录系统,重新设置密码。"
;
// 创建StringBuffer对象用来操作字符串
StringBuffer
sb
=
new
StringBuffer
(
"http://api.cnsms.cn/?"
);
// 向StringBuffer追加用户名
sb
.
append
(
"ac=send&uid="
);
//设置用户名
// 向StringBuffer追加密码(密码采用MD5 32位 小写)
sb
.
append
(
"&encode=utf8"
);
// 向StringBuffer追加密码(密码采用MD5 32位 小写)
sb
.
append
(
"&pwd="
);
//设置密码
// 向StringBuffer追加手机号码
sb
.
append
(
"&mobile="
+
tel
);
// 向StringBuffer追加消息内容转URL标准码
sb
.
append
(
"&content="
+
URLEncoder
.
encode
(
content
,
"utf8"
));
// 创建url对象
URL
url
=
new
URL
(
sb
.
toString
());
// 打开url连接
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
// 设置url请求方式 ‘get’ 或者 ‘post’
connection
.
setRequestMethod
(
"POST"
);
// 发送
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
url
.
openStream
()));
// 返回发送结果
String
inputline
=
in
.
readLine
();
return
inputline
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/common/spring/SpringUtils.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.spring
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.stereotype.Component
;
/**
* spring工具类 方便在非spring管理环境中获取bean
*
* @author JeeSpring
*/
@Component
public
final
class
SpringUtils
implements
BeanFactoryPostProcessor
{
/** Spring应用上下文环境 */
private
static
ConfigurableListableBeanFactory
beanFactory
;
@Override
public
void
postProcessBeanFactory
(
ConfigurableListableBeanFactory
beanFactory
)
throws
BeansException
{
SpringUtils
.
beanFactory
=
beanFactory
;
}
/**
* 获取对象
*
* @param name
* @return Object 一个以所给名字注册的bean的实例
* @throws org.springframework.beans.BeansException
*
*/
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
T
getBean
(
String
name
)
throws
BeansException
{
return
(
T
)
beanFactory
.
getBean
(
name
);
}
/**
* 获取类型为requiredType的对象
*
* @param clz
* @return
* @throws org.springframework.beans.BeansException
*
*/
public
static
<
T
>
T
getBean
(
Class
<
T
>
clz
)
throws
BeansException
{
T
result
=
(
T
)
beanFactory
.
getBean
(
clz
);
return
result
;
}
/**
* 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
*
* @param name
* @return boolean
*/
public
static
boolean
containsBean
(
String
name
)
{
return
beanFactory
.
containsBean
(
name
);
}
/**
* 判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)
*
* @param name
* @return boolean
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public
static
boolean
isSingleton
(
String
name
)
throws
NoSuchBeanDefinitionException
{
return
beanFactory
.
isSingleton
(
name
);
}
/**
* @param name
* @return Class 注册对象的类型
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public
static
Class
<?>
getType
(
String
name
)
throws
NoSuchBeanDefinitionException
{
return
beanFactory
.
getType
(
name
);
}
/**
* 如果给定的bean名字在bean定义中有别名,则返回这些别名
*
* @param name
* @return
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public
static
String
[]
getAliases
(
String
name
)
throws
NoSuchBeanDefinitionException
{
return
beanFactory
.
getAliases
(
name
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/swagger/Swagger.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.swagger
;
import
com.google.common.base.Predicates
;
import
com.jeespring.common.web.AbstractBaseController
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@Configuration
@EnableSwagger2
public
class
Swagger
{
@Bean
(
"JeeSpring云接口"
)
public
Docket
createJeeSpringRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
groupName
(
"JeeSpring云接口"
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
//这里采用包含注解的方式来确定要显示的接口
//.apis(RequestHandlerSelectors.basePackage("com.jeespring.modules")) //这里采用包扫描的方式来确定要显示的接口
//.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
//.paths(PathSelectors.regex("/rest/.*"))
//.paths(PathSelectors.any())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"Swagger2构建RESTful APIs"
)
.
description
(
"更多JeeSpring相关文章"
)
.
termsOfServiceUrl
(
"http://www.jeespring.com/"
)
.
contact
(
"contact"
)
.
version
(
"1.0"
)
.
build
();
}
/*注解
@ApiOperation(value="创建用户", notes="根据User对象创建用户")
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
@ApiOperation("生成代码")
@ApiImplicitParams({
@ApiImplicitParam(name = "moduleName", value = "模块名称", required = true, dataType = "String"),
@ApiImplicitParam(name = "bizChName", value = "业务名称", required = true, dataType = "String"),
@ApiImplicitParam(name = "bizEnName", value = "业务英文名称", required = true, dataType = "String"),
@ApiImplicitParam(name = "path", value = "项目生成类路径", required = true, dataType = "String")
})
*/
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/common/tag/AceMenuTag.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.tag
;
import
java.io.IOException
;
import
java.util.List
;
import
javax.servlet.ServletContext
;
import
javax.servlet.jsp.JspTagException
;
import
javax.servlet.jsp.JspWriter
;
import
javax.servlet.jsp.tagext.TagSupport
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.utils.SpringContextHolder
;
import
com.jeespring.modules.sys.entity.Menu
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
*
* 类描述:菜单标签
*
* 刘高峰
*
* @date: 日期:2015-1-23 时间:上午10:17:45
* @version 1.0
*/
public
class
AceMenuTag
extends
TagSupport
{
private
static
final
long
serialVersionUID
=
1L
;
protected
Menu
menu
;
// 菜单Map
public
Menu
getMenu
()
{
return
menu
;
}
public
void
setMenu
(
Menu
menu
)
{
this
.
menu
=
menu
;
}
@Override
public
int
doStartTag
()
throws
JspTagException
{
return
EVAL_PAGE
;
}
@Override
public
int
doEndTag
()
throws
JspTagException
{
try
{
JspWriter
out
=
this
.
pageContext
.
getOut
();
String
menu
=
(
String
)
this
.
pageContext
.
getSession
().
getAttribute
(
"menu"
);
if
(
menu
!=
null
)
{
out
.
print
(
menu
);
}
else
{
menu
=
end
().
toString
();
out
.
print
(
menu
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
EVAL_PAGE
;
}
public
StringBuffer
end
()
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
getChildOfTree
(
menu
,
0
,
UserUtils
.
getMenuList
()));
System
.
out
.
println
(
sb
);
return
sb
;
}
private
static
String
getChildOfTree
(
Menu
parent
,
int
level
,
List
<
Menu
>
menuList
)
{
StringBuffer
menuString
=
new
StringBuffer
();
String
href
=
""
;
if
(!
parent
.
hasPermisson
())
{
return
""
;
}
ServletContext
context
=
SpringContextHolder
.
getBean
(
ServletContext
.
class
);
if
(
parent
.
getHref
()
!=
null
&&
parent
.
getHref
().
length
()
>
0
)
{
if
(
parent
.
getHref
().
endsWith
(
".html"
)
&&
!
parent
.
getHref
().
endsWith
(
"ckfinder.html"
))
{
// 如果是静态资源并且不是ckfinder.html,直接访问不加adminPath
href
=
context
.
getContextPath
()
+
parent
.
getHref
();
}
else
{
href
=
context
.
getContextPath
()
+
Global
.
getAdminPath
()
+
parent
.
getHref
();
}
}
if
(
level
>
0
)
{
// level 为0是功能菜单
menuString
.
append
(
"<li>"
);
if
((
parent
.
getHref
()
==
null
||
""
.
equals
(
parent
.
getHref
().
trim
()))
&&
"1"
.
equals
(
parent
.
getIsShow
()))
{
menuString
.
append
(
"<a href=\""
+
href
+
"\" class=\"dropdown-toggle\">"
);
}
else
{
menuString
.
append
(
"<a class=\"J_menuItem\" href=\""
+
href
+
"\">"
);
}
menuString
.
append
(
"<i class=\"menu-icon fa "
+
parent
.
getIcon
()
+
"\"></i>"
);
menuString
.
append
(
"<span class=\"menu-text\">"
+
parent
.
getName
()+
"</span>"
);
if
((
parent
.
getHref
()
==
null
||
""
.
equals
(
parent
.
getHref
().
trim
()))
&&
"1"
.
equals
(
parent
.
getIsShow
()))
{
menuString
.
append
(
"<b class=\"arrow fa fa-angle-down\"></b>"
);
}
menuString
.
append
(
"</a>"
);
menuString
.
append
(
"<b class=\"arrow\"></b>"
);
}
if
((
parent
.
getHref
()
==
null
||
""
.
equals
(
parent
.
getHref
().
trim
()))
&&
"1"
.
equals
(
parent
.
getIsShow
()))
{
if
(
level
==
0
)
{
menuString
.
append
(
"<ul class=\"nav nav-list\">"
);
}
else
{
menuString
.
append
(
"<ul class=\"submenu\">"
);
}
for
(
Menu
child
:
menuList
)
{
if
(
child
.
getParentId
().
equals
(
parent
.
getId
())&&
"1"
.
equals
(
child
.
getIsShow
()))
{
menuString
.
append
(
getChildOfTree
(
child
,
level
+
1
,
menuList
));
}
}
menuString
.
append
(
"</ul>"
);
}
if
(
level
>
0
)
{
menuString
.
append
(
"</li>"
);
}
return
menuString
.
toString
();
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/tag/MenuTag.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.tag
;
import
java.io.IOException
;
import
javax.servlet.ServletContext
;
import
javax.servlet.jsp.JspTagException
;
import
javax.servlet.jsp.JspWriter
;
import
javax.servlet.jsp.tagext.TagSupport
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.utils.SpringContextHolder
;
import
com.jeespring.modules.sys.entity.Menu
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
*
* 类描述:菜单标签
*
*
* @date: 日期:2012-12-7 时间:上午10:17:45
* @version 1.0
*/
public
class
MenuTag
extends
TagSupport
{
private
static
final
long
serialVersionUID
=
1L
;
protected
Menu
menu
;
//菜单Map
public
Menu
getMenu
()
{
return
menu
;
}
public
void
setMenu
(
Menu
menu
)
{
this
.
menu
=
menu
;
}
@Override
public
int
doStartTag
()
throws
JspTagException
{
return
EVAL_PAGE
;
}
@Override
public
int
doEndTag
()
throws
JspTagException
{
try
{
JspWriter
out
=
this
.
pageContext
.
getOut
();
String
menu
=
(
String
)
this
.
pageContext
.
getSession
().
getAttribute
(
"menu"
);
if
(
menu
!=
null
){
out
.
print
(
menu
);
}
else
{
menu
=
end
().
toString
();
out
.
print
(
menu
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
EVAL_PAGE
;
}
public
StringBuffer
end
()
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
getChildOfTree
(
menu
,
0
));
//System.out.println(sb);
return
sb
;
}
private
static
String
getChildOfTree
(
Menu
parent
,
int
level
)
{
StringBuffer
menuString
=
new
StringBuffer
();
String
href
=
""
;
if
(!
parent
.
hasPermisson
())
{
return
""
;
}
if
(
level
>
0
)
{
//level 为0是功能菜单
if
(
parent
.
hasChildren
())
//menu-open
{
menuString
.
append
(
"<li class=\"treeview\">"
);
}
else
{
menuString
.
append
(
"<li>"
);
}
ServletContext
context
=
SpringContextHolder
.
getBean
(
ServletContext
.
class
);
if
(
parent
.
getHref
()
!=
null
&&
parent
.
getHref
().
length
()
>
0
)
{
if
(
parent
.
getHref
().
endsWith
(
".html"
)&&!
parent
.
getHref
().
endsWith
(
"ckfinder.html"
)){
//如果是静态资源并且不是ckfinder.html,直接访问不加adminPath
href
=
context
.
getContextPath
()
+
parent
.
getHref
();
}
else
if
(
parent
.
getHref
().
contains
(
"http://"
)
||
parent
.
getHref
().
contains
(
"https://"
)){
href
=
context
.
getContextPath
()
+
parent
.
getHref
();
}
else
{
href
=
context
.
getContextPath
()
+
Global
.
getAdminPath
()
+
parent
.
getHref
();
}
}
}
if
(
parent
.
hasChildren
())
{
if
(
level
>
0
)
{
menuString
.
append
(
"<a title=\""
+
parent
.
getName
()+
"\" href=\"javascript:\" data-href=\"blank\" class=\"nav-link\" href=\""
+
href
+
"\"><i class=\"fa "
+
parent
.
getIcon
()+
"\"></i> <span class=\"nav-label\">"
+
parent
.
getName
()
//+ "</span><span class=\"fa arrow\"></span></a>");
+
"</span><span class=\"pull-right-container\"><i class=\"fa fa-angle-left pull-right\"></i></span></a>"
);
}
if
(
level
==
1
)
{
menuString
.
append
(
"<ul class=\"nav nav-second-level treeview-menu\" >"
);
}
else
if
(
level
==
2
)
{
menuString
.
append
(
"<ul class=\"nav nav-third-level treeview-menu\" >"
);
}
else
if
(
level
==
3
)
{
menuString
.
append
(
"<ul class=\"nav nav-forth-level treeview-menu\" >"
);
}
else
if
(
level
==
4
)
{
menuString
.
append
(
"<ul class=\"nav nav-fifth-level treeview-menu\" >"
);
}
for
(
Menu
child
:
parent
.
getChildren
())
{
if
(
"1"
.
equals
(
child
.
getIsShow
()))
{
menuString
.
append
(
getChildOfTree
(
child
,
level
+
1
));
}
}
if
(
level
>
0
)
{
menuString
.
append
(
"</ul>"
);
}
}
else
{
//javascript:
menuString
.
append
(
"<a title=\""
+
parent
.
getName
()+
"\" class=\"nav-link\" target=\""
+
parent
.
getTarget
()+
"\" href=\""
+
href
+
"\" data-href=\""
+
href
+
"\"><i class=\"fa "
+
parent
.
getIcon
()+
"\"></i> <span class=\"nav-label\">"
+
parent
.
getName
()+
"</span></a>"
);
}
if
(
level
>
0
)
{
menuString
.
append
(
"</li>"
);
}
return
menuString
.
toString
();
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/tag/echarts/EChartsBarTag.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.tag.echarts
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.jsp.JspException
;
import
javax.servlet.jsp.tagext.BodyTag
;
import
javax.servlet.jsp.tagext.BodyTagSupport
;
import
javax.servlet.jsp.tagext.Tag
;
import
com.github.abel533.echarts.axis.CategoryAxis
;
import
com.github.abel533.echarts.axis.ValueAxis
;
import
com.github.abel533.echarts.code.*
;
import
com.github.abel533.echarts.feature.MagicType
;
import
com.github.abel533.echarts.json.GsonOption
;
import
com.github.abel533.echarts.series.Line
;
public
class
EChartsBarTag
extends
BodyTagSupport
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
private
String
title
;
private
String
subtitle
;
private
String
xAxisName
;
private
String
yAxisName
;
private
List
<
String
>
xAxisData
;
private
Map
<
String
,
Integer
>
yAxisIndex
;
private
Map
<
String
,
List
<
Double
>>
yAxisData
;
@Override
public
int
doStartTag
()
throws
JspException
{
return
BodyTag
.
EVAL_BODY_BUFFERED
;
}
@Override
public
int
doEndTag
()
throws
JspException
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<script type='text/javascript'>"
);
sb
.
append
(
"require([ 'echarts', 'echarts/chart/bar'], function(ec) {"
);
sb
.
append
(
"var myChart= ec.init(document.getElementById('"
+
id
+
"'));"
);
// 创建GsonOption对象,即为json字符串
GsonOption
option
=
new
GsonOption
();
option
.
tooltip
().
trigger
(
Trigger
.
axis
);
option
.
title
(
title
,
subtitle
);
// 工具栏
option
.
toolbox
().
show
(
true
).
feature
(
Tool
.
mark
,
Tool
.
dataView
,
Tool
.
saveAsImage
,
//new MagicType(Magic.line, Magic.bar,Magic.stack,Magic.tiled),
Tool
.
dataZoom
,
Tool
.
restore
);
option
.
calculable
(
true
);
option
.
dataZoom
().
show
(
true
).
realtime
(
true
).
start
(
0
).
end
(
100
);
// X轴数据封装并解析
ValueAxis
valueAxis
=
new
ValueAxis
();
for
(
String
s
:
xAxisData
)
{
valueAxis
.
type
(
AxisType
.
category
).
data
(
s
);
}
// X轴单位
valueAxis
.
name
(
xAxisName
);
option
.
xAxis
(
valueAxis
);
for
(
String
key
:
yAxisData
.
keySet
())
{
option
.
legend
().
data
(
key
);
}
// Y轴数据封装并解析
String
[]
unitNameArray
=
yAxisName
.
split
(
","
);
for
(
String
s
:
unitNameArray
)
{
CategoryAxis
categoryAxis
=
new
CategoryAxis
();
categoryAxis
.
type
(
AxisType
.
value
);
option
.
yAxis
(
categoryAxis
.
name
(
s
));
}
int
i
=
0
;
for
(
String
key
:
yAxisData
.
keySet
())
{
// 遍历list得到数据
List
<
Double
>
list
=
yAxisData
.
get
(
key
);
Line
line
=
new
Line
().
name
(
key
);
for
(
Double
d
:
list
)
{
// KW与MW单位的转换
// if(settingGlobal!=null&&settingGlobal.getIskw()==0){
// d = d/1000;
// }
// 数据为空的话会报错,为空则为零
if
(
d
!=
null
)
{
line
.
type
(
SeriesType
.
bar
).
data
(
d
);
}
else
{
line
.
type
(
SeriesType
.
bar
).
data
(
0
);
}
if
(
yAxisIndex
!=
null
&&
yAxisIndex
.
get
(
key
)
!=
null
)
{
line
.
type
(
SeriesType
.
bar
).
yAxisIndex
(
yAxisIndex
.
get
(
key
));
line
.
symbol
(
Symbol
.
none
);
}
else
{
line
.
type
(
SeriesType
.
bar
).
yAxisIndex
(
0
);
line
.
symbol
(
Symbol
.
none
);
}
}
option
.
series
(
line
);
i
++;
}
sb
.
append
(
"var option="
+
option
.
toString
()
+
";"
);
sb
.
append
(
"myChart.setOption(option);"
);
sb
.
append
(
"});"
);
sb
.
append
(
"</script>"
);
try
{
this
.
pageContext
.
getOut
().
write
(
sb
.
toString
());
}
catch
(
IOException
e
)
{
System
.
err
.
print
(
e
);
}
return
Tag
.
EVAL_PAGE
;
// 继续处理页面
}
@Override
public
String
getId
()
{
return
id
;
}
@Override
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getSubtitle
()
{
return
subtitle
;
}
public
void
setSubtitle
(
String
subtitle
)
{
this
.
subtitle
=
subtitle
;
}
public
String
getxAxisName
()
{
return
xAxisName
;
}
public
void
setxAxisName
(
String
xAxisName
)
{
this
.
xAxisName
=
xAxisName
;
}
public
String
getyAxisName
()
{
return
yAxisName
;
}
public
void
setyAxisName
(
String
yAxisName
)
{
this
.
yAxisName
=
yAxisName
;
}
public
List
<
String
>
getxAxisData
()
{
return
xAxisData
;
}
public
void
setxAxisData
(
List
<
String
>
xAxisData
)
{
this
.
xAxisData
=
xAxisData
;
}
public
Map
<
String
,
Integer
>
getyAxisIndex
()
{
return
yAxisIndex
;
}
public
void
setyAxisIndex
(
Map
<
String
,
Integer
>
yAxisIndex
)
{
this
.
yAxisIndex
=
yAxisIndex
;
}
public
Map
<
String
,
List
<
Double
>>
getyAxisData
()
{
return
yAxisData
;
}
public
void
setyAxisData
(
Map
<
String
,
List
<
Double
>>
yAxisData
)
{
this
.
yAxisData
=
yAxisData
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/tag/echarts/EChartsLineDoubleNumTag.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.tag.echarts
;
import
java.io.IOException
;
import
java.util.Map
;
import
javax.servlet.jsp.JspException
;
import
javax.servlet.jsp.tagext.BodyTag
;
import
javax.servlet.jsp.tagext.BodyTagSupport
;
import
javax.servlet.jsp.tagext.Tag
;
import
com.github.abel533.echarts.axis.CategoryAxis
;
import
com.github.abel533.echarts.axis.ValueAxis
;
import
com.github.abel533.echarts.code.*
;
import
com.github.abel533.echarts.feature.MagicType
;
import
com.github.abel533.echarts.json.GsonOption
;
import
com.github.abel533.echarts.series.Line
;
import
com.github.abel533.echarts.style.LineStyle
;
public
class
EChartsLineDoubleNumTag
extends
BodyTagSupport
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
private
String
title
;
private
String
subtitle
;
private
String
xAxisName
;
private
String
yAxisName
;
private
Map
<
String
,
Integer
>
yAxisIndex
;
private
Map
<
String
,
Double
[][]>
axisDataArr
;
@Override
public
int
doStartTag
()
throws
JspException
{
return
BodyTag
.
EVAL_BODY_BUFFERED
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
int
doEndTag
()
throws
JspException
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<script type='text/javascript'>"
);
sb
.
append
(
"require([ 'echarts', 'echarts/chart/line'], function(ec) {"
);
sb
.
append
(
"var myChart= ec.init(document.getElementById('"
+
id
+
"'));"
);
// 创建GsonOption对象,即为json字符串
GsonOption
option
=
new
GsonOption
();
/**
* tooltip : { trigger: 'axis' }
*/
option
.
tooltip
().
trigger
(
Trigger
.
axis
);
option
.
tooltip
().
axisPointer
().
show
(
true
).
type
(
PointerType
.
cross
)
.
lineStyle
(
new
LineStyle
().
type
(
LineType
.
dashed
).
width
(
1
));
/**
* title : { 'text':'2002全国宏观经济关联分析(GDP vs 房地产)', 'subtext':'数据来自国家统计局'
* }
*/
option
.
title
(
title
,
subtitle
);
/**
* toolbox: { show : true, feature : { mark : {show: true}, dataZoom :
* {show: true}, dataView : {show: true}, magicType : {show: true, type:
* ['line', 'bar', 'stack', 'tiled']}, restore : {show: true},
* saveAsImage : {show: true} } }
*/
// 工具栏
option
.
toolbox
().
show
(
true
).
feature
(
Tool
.
mark
,
Tool
.
dataZoom
,
Tool
.
dataView
,
//new MagicType(Magic.line, Magic.bar,Magic.stack,Magic.tiled),
Tool
.
restore
,
Tool
.
saveAsImage
);
option
.
calculable
(
true
);
option
.
dataZoom
().
show
(
true
).
realtime
(
true
).
start
(
0
).
end
(
100
);
/**
* xAxis : [ { type: 'value' } ]
*/
// X轴数据设置类型
ValueAxis
valueAxis
=
new
ValueAxis
();
valueAxis
.
type
(
AxisType
.
value
);
valueAxis
.
name
(
xAxisName
);
option
.
xAxis
(
valueAxis
);
// Y轴数据设置类型
CategoryAxis
categoryAxis
=
new
CategoryAxis
();
categoryAxis
.
type
(
AxisType
.
value
);
categoryAxis
.
name
(
yAxisName
);
option
.
yAxis
(
categoryAxis
);
for
(
String
xtitle
:
axisDataArr
.
keySet
())
{
option
.
legend
().
data
(
xtitle
);
}
for
(
String
mapkey
:
axisDataArr
.
keySet
())
{
Line
line
=
new
Line
();
// 显示直线,而不是密密麻麻的点,一点都不好看
line
.
name
(
mapkey
).
type
(
SeriesType
.
line
).
symbol
(
Symbol
.
none
);
Object
[][]
dataArr
=
(
Double
[][])
axisDataArr
.
get
(
mapkey
);
for
(
int
num
=
0
;
num
<
dataArr
.
length
;
num
++)
{
line
.
data
().
add
(
dataArr
[
num
]);
}
if
(
yAxisIndex
!=
null
&&
yAxisIndex
.
get
(
mapkey
)
!=
null
)
{
line
.
yAxisIndex
(
yAxisIndex
.
get
(
mapkey
));
}
else
{
line
.
yAxisIndex
(
0
);
}
option
.
series
(
line
);
}
sb
.
append
(
"var option="
+
option
.
toString
()+
";"
);
sb
.
append
(
"myChart.setOption(option);"
);
sb
.
append
(
"});"
);
sb
.
append
(
"</script>"
);
try
{
this
.
pageContext
.
getOut
().
write
(
sb
.
toString
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
Tag
.
EVAL_PAGE
;
// 继续处理页面
}
@Override
public
String
getId
()
{
return
id
;
}
@Override
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getSubtitle
()
{
return
subtitle
;
}
public
void
setSubtitle
(
String
subtitle
)
{
this
.
subtitle
=
subtitle
;
}
public
String
getxAxisName
()
{
return
xAxisName
;
}
public
void
setxAxisName
(
String
xAxisName
)
{
this
.
xAxisName
=
xAxisName
;
}
public
String
getyAxisName
()
{
return
yAxisName
;
}
public
void
setyAxisName
(
String
yAxisName
)
{
this
.
yAxisName
=
yAxisName
;
}
public
Map
<
String
,
Integer
>
getyAxisIndex
()
{
return
yAxisIndex
;
}
public
void
setyAxisIndex
(
Map
<
String
,
Integer
>
yAxisIndex
)
{
this
.
yAxisIndex
=
yAxisIndex
;
}
public
Map
<
String
,
Double
[][]>
getAxisDataArr
()
{
return
axisDataArr
;
}
public
void
setAxisDataArr
(
Map
<
String
,
Double
[][]>
axisDataArr
)
{
this
.
axisDataArr
=
axisDataArr
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/tag/echarts/EChartsLineTag.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.tag.echarts
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.jsp.JspException
;
import
javax.servlet.jsp.tagext.BodyTag
;
import
javax.servlet.jsp.tagext.BodyTagSupport
;
import
javax.servlet.jsp.tagext.Tag
;
import
com.github.abel533.echarts.axis.CategoryAxis
;
import
com.github.abel533.echarts.axis.ValueAxis
;
import
com.github.abel533.echarts.code.*
;
import
com.github.abel533.echarts.feature.MagicType
;
import
com.github.abel533.echarts.json.GsonOption
;
import
com.github.abel533.echarts.series.Line
;
public
class
EChartsLineTag
extends
BodyTagSupport
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
private
String
title
;
private
String
subtitle
;
private
String
xAxisName
;
private
String
yAxisName
;
private
List
<
String
>
xAxisData
;
private
Map
<
String
,
Integer
>
yAxisIndex
;
private
Map
<
String
,
List
<
Double
>>
yAxisData
;
@Override
public
int
doStartTag
()
throws
JspException
{
return
BodyTag
.
EVAL_BODY_BUFFERED
;
}
@Override
public
int
doEndTag
()
throws
JspException
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<script type='text/javascript'>"
);
sb
.
append
(
"require([ 'echarts', 'echarts/chart/line','echarts/chart/bar'], function(ec) {"
);
sb
.
append
(
"var myChart= ec.init(document.getElementById('"
+
id
+
"'));"
);
// 创建GsonOption对象,即为json字符串
GsonOption
option
=
new
GsonOption
();
option
.
tooltip
().
trigger
(
Trigger
.
axis
);
option
.
title
(
title
,
subtitle
);
// 工具栏
option
.
toolbox
().
show
(
true
).
feature
(
Tool
.
mark
,
Tool
.
dataView
,
Tool
.
saveAsImage
,
Tool
.
magicType
,
new
MagicType
(
Magic
.
line
,
Magic
.
bar
,
Magic
.
stack
,
Magic
.
tiled
),
Tool
.
dataZoom
,
Tool
.
restore
);
option
.
calculable
(
true
);
option
.
dataZoom
().
show
(
true
).
realtime
(
true
).
start
(
0
).
end
(
100
);
// X轴数据封装并解析
ValueAxis
valueAxis
=
new
ValueAxis
();
for
(
String
s
:
xAxisData
)
{
valueAxis
.
type
(
AxisType
.
category
).
data
(
s
);
}
// X轴单位
valueAxis
.
name
(
xAxisName
);
option
.
xAxis
(
valueAxis
);
for
(
String
key
:
yAxisData
.
keySet
())
{
option
.
legend
().
data
(
key
);
}
// Y轴数据封装并解析
String
[]
unitNameArray
=
yAxisName
.
split
(
","
);
for
(
String
s
:
unitNameArray
)
{
CategoryAxis
categoryAxis
=
new
CategoryAxis
();
categoryAxis
.
type
(
AxisType
.
value
);
option
.
yAxis
(
categoryAxis
.
name
(
s
));
}
int
i
=
0
;
for
(
String
key
:
yAxisData
.
keySet
())
{
// 遍历list得到数据
List
<
Double
>
list
=
yAxisData
.
get
(
key
);
Line
line
=
new
Line
().
name
(
key
);
for
(
Double
d
:
list
)
{
// KW与MW单位的转换
// if(settingGlobal!=null&&settingGlobal.getIskw()==0){
// d = d/1000;
// }
// 数据为空的话会报错,为空则为零
if
(
d
!=
null
)
{
line
.
type
(
SeriesType
.
line
).
data
(
d
);
}
else
{
line
.
type
(
SeriesType
.
line
).
data
(
0
);
}
if
(
yAxisIndex
!=
null
&&
yAxisIndex
.
get
(
key
)
!=
null
)
{
line
.
type
(
SeriesType
.
line
).
yAxisIndex
(
yAxisIndex
.
get
(
key
));
line
.
symbol
(
Symbol
.
none
);
}
else
{
line
.
type
(
SeriesType
.
line
).
yAxisIndex
(
0
);
//显示直线,而不是密密麻麻的点,一点都不好看
line
.
symbol
(
Symbol
.
none
);
}
}
option
.
series
(
line
);
i
++;
}
sb
.
append
(
"var option="
+
option
.
toString
()+
";"
);
sb
.
append
(
"myChart.setOption(option);"
);
sb
.
append
(
"});"
);
sb
.
append
(
"</script>"
);
try
{
this
.
pageContext
.
getOut
().
write
(
sb
.
toString
());
}
catch
(
IOException
e
)
{
System
.
err
.
print
(
e
);
}
return
Tag
.
EVAL_PAGE
;
// 继续处理页面
}
@Override
public
String
getId
()
{
return
id
;
}
@Override
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getSubtitle
()
{
return
subtitle
;
}
public
void
setSubtitle
(
String
subtitle
)
{
this
.
subtitle
=
subtitle
;
}
public
String
getxAxisName
()
{
return
xAxisName
;
}
public
void
setxAxisName
(
String
xAxisName
)
{
this
.
xAxisName
=
xAxisName
;
}
public
String
getyAxisName
()
{
return
yAxisName
;
}
public
void
setyAxisName
(
String
yAxisName
)
{
this
.
yAxisName
=
yAxisName
;
}
public
List
<
String
>
getxAxisData
()
{
return
xAxisData
;
}
public
void
setxAxisData
(
List
<
String
>
xAxisData
)
{
this
.
xAxisData
=
xAxisData
;
}
public
Map
<
String
,
Integer
>
getyAxisIndex
()
{
return
yAxisIndex
;
}
public
void
setyAxisIndex
(
Map
<
String
,
Integer
>
yAxisIndex
)
{
this
.
yAxisIndex
=
yAxisIndex
;
}
public
Map
<
String
,
List
<
Double
>>
getyAxisData
()
{
return
yAxisData
;
}
public
void
setyAxisData
(
Map
<
String
,
List
<
Double
>>
yAxisData
)
{
this
.
yAxisData
=
yAxisData
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/tag/echarts/EChartsLineTimeLineTag.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.tag.echarts
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.jsp.JspException
;
import
javax.servlet.jsp.tagext.BodyTag
;
import
javax.servlet.jsp.tagext.BodyTagSupport
;
import
javax.servlet.jsp.tagext.Tag
;
import
com.github.abel533.echarts.axis.CategoryAxis
;
import
com.github.abel533.echarts.axis.ValueAxis
;
import
com.github.abel533.echarts.code.*
;
import
com.github.abel533.echarts.feature.MagicType
;
import
com.github.abel533.echarts.json.GsonOption
;
import
com.github.abel533.echarts.series.Line
;
public
class
EChartsLineTimeLineTag
extends
BodyTagSupport
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
private
String
title
;
private
String
subtitle
;
private
String
xAxisName
;
private
String
yAxisName
;
private
List
<
String
>
xAxisData
;
private
Map
<
String
,
Integer
>
yAxisIndex
;
private
Map
<
String
,
List
<
Double
>>
yAxisData
;
private
List
<
String
>
timelineData
;
private
List
<
Map
<
String
,
List
<
Double
>>>
timelineAxisData
;
@Override
public
int
doStartTag
()
throws
JspException
{
return
BodyTag
.
EVAL_BODY_BUFFERED
;
}
@Override
public
int
doEndTag
()
throws
JspException
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<script type='text/javascript'>"
);
sb
.
append
(
"require([ 'echarts', 'echarts/chart/line'], function(ec) {"
);
sb
.
append
(
"var myChart= ec.init(document.getElementById('"
+
id
+
"'));"
);
GsonOption
option
=
new
GsonOption
();
GsonOption
options
=
new
GsonOption
();
/**
* timeline:{ data:[
* '2002-01-01','2003-01-01','2004-01-01','2005-01-01','2006-01-01',
* '2007-01-01','2008-01-01','2009-01-01','2010-01-01','2011-01-01' ],
* label : { formatter : function(s) { return s.slice(0, 4); } },
* autoPlay : true, playInterval : 1000 },
*/
option
.
timeline
().
autoPlay
(
true
).
playInterval
(
1000
).
label
()
.
formatter
(
"function(s){return s.slice(0, 4);}"
);
for
(
String
key
:
timelineData
)
{
option
.
timeline
().
data
(
key
);
}
/**
* title : { 'text':'2002全国宏观经济指标', 'subtext':'数据来自国家统计局' },
*/
options
.
title
(
title
,
subtitle
);
/**
* tooltip : {'trigger':'axis'},
*/
options
.
tooltip
().
trigger
(
Trigger
.
axis
);
/**
* legend : { x:'right', 'data':['GDP','金融','房地产','第一产业','第二产业','第三产业'],
* 'selected':{ 'GDP':true, '金融':false, '房地产':true, '第一产业':false,
* '第二产业':false, '第三产业':false } },
*/
options
.
legend
().
x
(
X
.
right
);
for
(
String
key
:
yAxisData
.
keySet
())
{
options
.
legend
().
data
(
key
);
}
/**
* toolbox : { 'show':true, orient : 'vertical', x: 'right', y:
* 'center', 'feature':{ 'mark':{'show':true},
* 'dataView':{'show':true,'readOnly':false},
* 'magicType':{'show':true,'type':['line','bar','stack','tiled']},
* 'restore':{'show':true}, 'saveAsImage':{'show':true} } }, calculable
* : true,
*/
// 工具栏
options
.
toolbox
().
orient
(
Orient
.
vertical
).
x
(
X
.
right
).
y
(
Y
.
center
)
.
show
(
true
).
feature
(
Tool
.
mark
,
Tool
.
dataView
,
Tool
.
saveAsImage
,
//new MagicType(Magic.line, Magic.bar,Magic.stack,Magic.tiled),
Tool
.
dataZoom
,
Tool
.
restore
);
options
.
calculable
(
true
);
options
.
dataZoom
().
show
(
true
).
realtime
(
true
).
start
(
0
).
end
(
100
);
/**
* xAxis : [{ 'type':'category', 'axisLabel':{'interval':0}, 'data':[
* '北京','\n天津','河北','\n山西','内蒙古','\n辽宁','吉林','\n黑龙江',
* '上海','\n江苏','浙江','\n安徽','福建','\n江西','山东','\n河南',
* '湖北','\n湖南','广东','\n广西','海南','\n重庆','四川','\n贵州',
* '云南','\n西藏','陕西','\n甘肃','青海','\n宁夏','新疆' ] }],
*/
// X轴数据封装并解析
ValueAxis
valueAxis
=
new
ValueAxis
();
for
(
String
s
:
xAxisData
)
{
valueAxis
.
type
(
AxisType
.
category
).
data
(
s
);
}
// X轴单位
valueAxis
.
name
(
xAxisName
);
options
.
xAxis
(
valueAxis
);
/**
* yAxis : [ { 'type':'value', 'name':'GDP(亿元)', 'max':53500 }, {
* 'type':'value', 'name':'其他(亿元)' } ],
*/
// Y轴数据封装并解析
String
[]
unitNameArray
=
yAxisName
.
split
(
","
);
for
(
String
s
:
unitNameArray
)
{
CategoryAxis
categoryAxis
=
new
CategoryAxis
();
categoryAxis
.
type
(
AxisType
.
value
);
options
.
yAxis
(
categoryAxis
.
name
(
s
));
}
for
(
String
key
:
yAxisData
.
keySet
())
{
// 遍历list得到数据
List
<
Double
>
list
=
yAxisData
.
get
(
key
);
Line
line
=
new
Line
().
name
(
key
);
for
(
Double
d
:
list
)
{
// KW与MW单位的转换
// if(settingGlobal!=null&&settingGlobal.getIskw()==0){
// d = d/1000;
// }
// 数据为空的话会报错,为空则为零
if
(
d
!=
null
)
{
line
.
type
(
SeriesType
.
line
).
data
(
d
);
}
else
{
line
.
type
(
SeriesType
.
line
).
data
(
0
);
}
if
(
yAxisIndex
!=
null
&&
yAxisIndex
.
get
(
key
)
!=
null
)
{
line
.
type
(
SeriesType
.
line
).
yAxisIndex
(
yAxisIndex
.
get
(
key
));
// 显示直线,而不是密密麻麻的点,一点都不好看
line
.
symbol
(
Symbol
.
none
);
}
else
{
line
.
type
(
SeriesType
.
line
).
yAxisIndex
(
0
);
line
.
symbol
(
Symbol
.
none
);
}
}
options
.
series
(
line
);
}
option
.
options
(
options
);
for
(
int
ii
=
1
;
ii
<
timelineData
.
size
();
ii
++)
{
Map
<
String
,
List
<
Double
>>
timelineAxisDataMap
=
timelineAxisData
.
get
(
ii
-
1
);
GsonOption
timeLineOption
=
new
GsonOption
();
timeLineOption
.
title
(
timelineData
.
get
(
ii
)
+
title
.
substring
(
4
,
title
.
length
()),
subtitle
);
for
(
String
key
:
timelineAxisDataMap
.
keySet
())
{
// 遍历list得到数据
List
<
Double
>
list
=
timelineAxisDataMap
.
get
(
key
);
Line
line
=
new
Line
().
name
(
key
);
for
(
Double
d
:
list
)
{
// KW与MW单位的转换
// if(settingGlobal!=null&&settingGlobal.getIskw()==0){
// d = d/1000;
// }
// 数据为空的话会报错,为空则为零
if
(
d
!=
null
)
{
line
.
type
(
SeriesType
.
line
).
data
(
d
);
}
else
{
line
.
type
(
SeriesType
.
line
).
data
(
0
);
}
if
(
yAxisIndex
!=
null
&&
yAxisIndex
.
get
(
key
)
!=
null
)
{
line
.
type
(
SeriesType
.
line
).
yAxisIndex
(
yAxisIndex
.
get
(
key
));
// 显示直线,而不是密密麻麻的点,一点都不好看
line
.
symbol
(
Symbol
.
none
);
}
else
{
line
.
type
(
SeriesType
.
line
).
yAxisIndex
(
0
);
line
.
symbol
(
Symbol
.
none
);
}
}
timeLineOption
.
series
(
line
);
}
option
.
options
(
timeLineOption
);
}
sb
.
append
(
"var option="
+
option
.
toString
()
+
";"
);
sb
.
append
(
"myChart.setOption(option);"
);
sb
.
append
(
"});"
);
sb
.
append
(
"</script>"
);
try
{
this
.
pageContext
.
getOut
().
write
(
sb
.
toString
());
}
catch
(
IOException
e
)
{
System
.
err
.
print
(
e
);
}
return
Tag
.
EVAL_PAGE
;
// 继续处理页面
}
@Override
public
String
getId
()
{
return
id
;
}
@Override
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getSubtitle
()
{
return
subtitle
;
}
public
void
setSubtitle
(
String
subtitle
)
{
this
.
subtitle
=
subtitle
;
}
public
String
getxAxisName
()
{
return
xAxisName
;
}
public
void
setxAxisName
(
String
xAxisName
)
{
this
.
xAxisName
=
xAxisName
;
}
public
String
getyAxisName
()
{
return
yAxisName
;
}
public
void
setyAxisName
(
String
yAxisName
)
{
this
.
yAxisName
=
yAxisName
;
}
public
List
<
String
>
getxAxisData
()
{
return
xAxisData
;
}
public
void
setxAxisData
(
List
<
String
>
xAxisData
)
{
this
.
xAxisData
=
xAxisData
;
}
public
Map
<
String
,
Integer
>
getyAxisIndex
()
{
return
yAxisIndex
;
}
public
void
setyAxisIndex
(
Map
<
String
,
Integer
>
yAxisIndex
)
{
this
.
yAxisIndex
=
yAxisIndex
;
}
public
Map
<
String
,
List
<
Double
>>
getyAxisData
()
{
return
yAxisData
;
}
public
void
setyAxisData
(
Map
<
String
,
List
<
Double
>>
yAxisData
)
{
this
.
yAxisData
=
yAxisData
;
}
public
List
<
String
>
getTimelineData
()
{
return
timelineData
;
}
public
void
setTimelineData
(
List
<
String
>
timelineData
)
{
this
.
timelineData
=
timelineData
;
}
public
List
<
Map
<
String
,
List
<
Double
>>>
getTimelineAxisData
()
{
return
timelineAxisData
;
}
public
void
setTimelineAxisData
(
List
<
Map
<
String
,
List
<
Double
>>>
timelineAxisData
)
{
this
.
timelineAxisData
=
timelineAxisData
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/tag/echarts/EChartsPieTag.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.tag.echarts
;
import
java.io.IOException
;
import
java.util.Map
;
import
javax.servlet.jsp.JspException
;
import
javax.servlet.jsp.tagext.BodyTag
;
import
javax.servlet.jsp.tagext.BodyTagSupport
;
import
javax.servlet.jsp.tagext.Tag
;
import
com.github.abel533.echarts.code.*
;
import
com.github.abel533.echarts.data.Data
;
import
com.github.abel533.echarts.feature.MagicType
;
import
com.github.abel533.echarts.json.GsonOption
;
import
com.github.abel533.echarts.series.Line
;
public
class
EChartsPieTag
extends
BodyTagSupport
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
private
String
title
;
private
String
subtitle
;
private
Map
<
String
,
Object
>
orientData
;
@Override
public
int
doStartTag
()
throws
JspException
{
return
BodyTag
.
EVAL_BODY_BUFFERED
;
}
@Override
public
int
doEndTag
()
throws
JspException
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<script type='text/javascript'>"
);
sb
.
append
(
"require([ 'echarts','echarts/chart/pie'], function(ec) {"
);
sb
.
append
(
"var myChart= ec.init(document.getElementById('"
+
id
+
"'));"
);
// 创建GsonOption对象,即为json字符串
GsonOption
option
=
new
GsonOption
();
option
.
tooltip
().
trigger
(
Trigger
.
item
).
formatter
(
"{a} <br/>{b} : {c} ({d}%)"
);
option
.
title
(
title
,
subtitle
);
// 工具栏
option
.
toolbox
().
show
(
true
).
feature
(
Tool
.
mark
,
Tool
.
dataView
,
Tool
.
saveAsImage
,
//Tool.magicType,
//new MagicType(Magic.line, Magic.bar,Magic.pie,Magic.stack,Magic.tiled),
Tool
.
dataZoom
,
Tool
.
restore
);
option
.
calculable
(
true
);
// 数据轴封装并解析
for
(
String
xdata
:
orientData
.
keySet
())
{
//option.legend().orient(Orient.horizontal).x(X.left).y(Y.bottom).data(xdata);
option
.
legend
().
orient
(
Orient
.
vertical
).
x
(
X
.
left
).
y
(
Y
.
bottom
).
data
(
xdata
);
}
if
(
orientData
!=
null
)
{
Line
line
=
new
Line
();
line
.
name
(
title
).
type
(
SeriesType
.
pie
);
for
(
String
title
:
orientData
.
keySet
())
{
Object
value
=
orientData
.
get
(
title
);
Data
data
=
new
Data
().
name
(
title
);
data
.
value
(
value
);
line
.
data
(
data
);
}
option
.
series
(
line
);
}
sb
.
append
(
"var option="
+
option
.
toString
()
+
";\n"
);
/*sb.append("option.series[0].label={\nnormal: { formatter: ' {b|{b}:}{c} {per|{d}%} ',");
sb.append("backgroundColor: '#eee',borderColor: '#aaa',borderWidth: 1,borderRadius: 4,");
sb.append("rich: {a: {color: '#999',lineHeight: 22,align: 'center'},");
sb.append("hr: {borderColor: '#aaa',width: '100%',borderWidth: 0.5,height: 0},");
sb.append("b: {fontSize: 16,lineHeight: 33},");
sb.append("per: {color: '#eee',backgroundColor: '#334455',padding: [2, 4],borderRadius: 2}");
sb.append("}}\n};\n");*/
sb
.
append
(
"myChart.setOption(option);\n"
);
sb
.
append
(
"});"
);
sb
.
append
(
"</script>"
);
try
{
this
.
pageContext
.
getOut
().
write
(
sb
.
toString
());
}
catch
(
IOException
e
)
{
System
.
err
.
print
(
e
);
}
return
Tag
.
EVAL_PAGE
;
// 继续处理页面
}
@Override
public
String
getId
()
{
return
id
;
}
@Override
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getSubtitle
()
{
return
subtitle
;
}
public
void
setSubtitle
(
String
subtitle
)
{
this
.
subtitle
=
subtitle
;
}
public
Map
<
String
,
Object
>
getOrientData
()
{
return
orientData
;
}
public
void
setOrientData
(
Map
<
String
,
Object
>
orientData
)
{
this
.
orientData
=
orientData
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/tag/echarts/EChartsRadarTag.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.tag.echarts
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.jsp.JspException
;
import
javax.servlet.jsp.tagext.BodyTag
;
import
javax.servlet.jsp.tagext.BodyTagSupport
;
import
javax.servlet.jsp.tagext.Tag
;
import
com.github.abel533.echarts.Polar
;
import
com.github.abel533.echarts.code.*
;
import
com.github.abel533.echarts.data.Data
;
import
com.github.abel533.echarts.feature.MagicType
;
import
com.github.abel533.echarts.json.GsonOption
;
import
com.github.abel533.echarts.series.Line
;
public
class
EChartsRadarTag
extends
BodyTagSupport
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
private
String
title
;
private
String
subtitle
;
private
Integer
polarType
;
private
List
<
Map
<
String
,
Object
>>
orientData
;
@Override
public
int
doStartTag
()
throws
JspException
{
return
BodyTag
.
EVAL_BODY_BUFFERED
;
}
@Override
public
int
doEndTag
()
throws
JspException
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<script type='text/javascript'>"
);
sb
.
append
(
"require([ 'echarts', 'echarts/chart/radar'], function(ec) {"
);
sb
.
append
(
"var myChart= ec.init(document.getElementById('"
+
id
+
"'));"
);
// 创建GsonOption对象,即为json字符串
GsonOption
option
=
new
GsonOption
();
/**
* title: { text: '实时风向玫瑰图', subtext: '预测时间:' },
*/
option
.
title
(
title
,
subtitle
);
/**
* tooltip: { trigger: 'axis' },
*/
option
.
tooltip
().
trigger
(
Trigger
.
axis
);
/**
* polar: [ { indicator: [ { text: '正北(N)', max: 100 }, { text:
* '西北(NW)', max: 100 }, { text: '正西(W)', max: 100 }, { text: '西南(SW)',
* max: 100 }, { text: '正南(S)', max: 100 }, { text: '东南(SE)', max: 100
* }, { text: '正东(E)', max: 100 }, { text: '东北(NE)', max: 100 } ] } ]
*/
// 工具栏
option
.
toolbox
().
show
(
true
).
feature
(
Tool
.
mark
,
Tool
.
dataView
,
Tool
.
saveAsImage
,
//new MagicType(Magic.line, Magic.bar,Magic.stack,Magic.tiled),
Tool
.
dataZoom
,
Tool
.
restore
);
Polar
polar
=
new
Polar
();
if
(
polarType
==
8
)
{
polar
.
indicator
(
new
Data
().
text
(
"正北(N)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"西北(NW)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"正西(W)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"西南(SW)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"正南(S)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"东南(SE)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"正东(E)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"东北(NE)"
).
max
(
100
));
}
else
if
(
polarType
==
16
)
{
polar
.
indicator
(
new
Data
().
text
(
"正北(N)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"北西北(NNW)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"西北(NW)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"西北西(WNW)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"正西(W)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"西南西(WSW)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"西南(SW)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"南西南(SSW)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"正南(S)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"南东南(SSE)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"东南(SE)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"东南东(ESE)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"正东(E)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"东北东(ENE)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"东北(NE)"
).
max
(
100
))
.
indicator
(
new
Data
().
text
(
"北东北(NNE)"
).
max
(
100
));
}
option
.
polar
(
polar
);
option
.
calculable
(
true
);
/**
* legend: { orient: 'horizontal', x: 'left', y: 'bottom', data: [
* <c:forEach var="item" items="${towerList}" varStatus="status">
* '${item.tower_mater}米风向', </c:forEach> ] },
*/
if
(
orientData
!=
null
)
{
for
(
Map
<
String
,
Object
>
legendMap
:
orientData
)
{
String
title
=
legendMap
.
get
(
"title"
).
toString
();
option
.
legend
().
orient
(
Orient
.
horizontal
).
x
(
X
.
left
).
y
(
Y
.
bottom
).
data
(
title
);
Line
line
=
new
Line
();
Data
data
=
new
Data
().
name
(
title
);
Object
[]
dataArr
=
(
Double
[])
legendMap
.
get
(
"dataArr"
);
data
.
value
(
dataArr
);
line
.
type
(
SeriesType
.
radar
).
data
(
data
);
option
.
series
(
line
);
}
}
sb
.
append
(
"var option="
+
option
.
toString
()+
";"
);
sb
.
append
(
"myChart.setOption(option);"
);
sb
.
append
(
"});"
);
sb
.
append
(
"</script>"
);
try
{
this
.
pageContext
.
getOut
().
write
(
sb
.
toString
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
Tag
.
EVAL_PAGE
;
// 继续处理页面
}
@Override
public
String
getId
()
{
return
id
;
}
@Override
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getSubtitle
()
{
return
subtitle
;
}
public
void
setSubtitle
(
String
subtitle
)
{
this
.
subtitle
=
subtitle
;
}
public
Integer
getPolarType
()
{
return
polarType
;
}
public
void
setPolarType
(
Integer
polarType
)
{
this
.
polarType
=
polarType
;
}
public
List
<
Map
<
String
,
Object
>>
getOrientData
()
{
return
orientData
;
}
public
void
setOrientData
(
List
<
Map
<
String
,
Object
>>
orientData
)
{
this
.
orientData
=
orientData
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/utils/AddressUtils.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.utils
;
import
com.alibaba.fastjson.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.jeespring.common.utils.http.HttpUtils
;
import
org.springframework.beans.factory.annotation.Value
;
/**
* 获取地址类
*
* @author JeeSpring
*/
public
class
AddressUtils
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AddressUtils
.
class
);
public
static
final
String
IP_URL
=
"http://ip.taobao.com/service/getIpInfo.php"
;
/** 获取地址开关 */
private
static
boolean
addressEnabled
=
false
;
public
static
String
getRealAddressByIP
(
String
ip
)
{
String
address
=
""
;
try
{
if
(
addressEnabled
)
{
address
=
HttpUtils
.
sendPost
(
IP_URL
,
"ip="
+
ip
);
JSONObject
json
=
JSONObject
.
parseObject
(
address
);
JSONObject
object
=
json
.
getObject
(
"data"
,
JSONObject
.
class
);
String
region
=
object
.
getString
(
"region"
);
String
city
=
object
.
getString
(
"city"
);
address
=
region
+
" "
+
city
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"获取地理位置异常:"
,
e
.
getMessage
());
}
return
address
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/utils/Base64ImageUtils.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.utils
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
/**
* Created by zhangwenchao on 2017/9/29.
* 本地或者网络图片资源转为Base64字符串
*/
public
class
Base64ImageUtils
{
/**
* @Title: GetImageStrFromUrl
* @Description: 将一张网络图片转化成Base64字符串
* @param imgURL 网络资源位置
* @return Base64字符串
*/
public
static
String
GetImageStrFromUrl
(
String
imgURL
)
{
byte
[]
data
=
null
;
try
{
// 创建URL
URL
url
=
new
URL
(
imgURL
);
// 创建链接
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setConnectTimeout
(
5
*
1000
);
InputStream
inStream
=
conn
.
getInputStream
();
data
=
new
byte
[
inStream
.
available
()];
inStream
.
read
(
data
);
inStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// 对字节数组Base64编码
BASE64Encoder
encoder
=
new
BASE64Encoder
();
// 返回Base64编码过的字节数组字符串
return
encoder
.
encode
(
data
);
}
/**
* @Title: GetImageStrFromPath
* @Description: (将一张本地图片转化成Base64字符串)
* @param imgPath
* @return
*/
public
static
String
GetImageStrFromPath
(
String
imgPath
)
{
InputStream
in
=
null
;
byte
[]
data
=
null
;
// 读取图片字节数组
try
{
in
=
new
FileInputStream
(
imgPath
);
data
=
new
byte
[
in
.
available
()];
in
.
read
(
data
);
in
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// 对字节数组Base64编码
BASE64Encoder
encoder
=
new
BASE64Encoder
();
// 返回Base64编码过的字节数组字符串
return
encoder
.
encode
(
data
);
}
/**
* @Title: GenerateImage
* @Description: base64字符串转化成图片
* @param imgStr
* @param imgFilePath 图片文件名,如“E:/tmp.jpg”
* @return
*/
public
static
boolean
saveImage
(
String
imgStr
,
String
imgFilePath
)
{
if
(
imgStr
==
null
)
// 图像数据为空
{
return
false
;
}
BASE64Decoder
decoder
=
new
BASE64Decoder
();
try
{
// Base64解码
byte
[]
b
=
decoder
.
decodeBuffer
(
imgStr
);
for
(
int
i
=
0
;
i
<
b
.
length
;
++
i
)
{
if
(
b
[
i
]
<
0
)
{
// 调整异常数据
b
[
i
]
+=
256
;
}
}
// 生成jpeg图片
OutputStream
out
=
new
FileOutputStream
(
imgFilePath
);
out
.
write
(
b
);
out
.
flush
();
out
.
close
();
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/utils/CacheUtils.java
0 → 100644
View file @
d5ba54ba
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.common.utils
;
import
org.apache.shiro.cache.Cache
;
import
org.apache.shiro.cache.CacheManager
;
/**
* Cache工具类
*
* @author 黄炳桂 516821420@qq.com
* @version 2013-5-29
*/
public
class
CacheUtils
{
private
static
CacheManager
cacheManager
=
SpringContextHolder
.
getBean
(
CacheManager
.
class
);
private
static
final
String
SYS_CACHE
=
"sysCache"
;
/**
* 获取SYS_CACHE缓存
*
* @param key
* @return
*/
public
static
Object
get
(
String
key
)
{
return
get
(
SYS_CACHE
,
key
);
}
/**
* 获取SYS_CACHE缓存
*
* @param key
* @param defaultValue
* @return
*/
public
static
Object
get
(
String
key
,
Object
defaultValue
)
{
Object
value
=
get
(
key
);
return
value
!=
null
?
value
:
defaultValue
;
}
/**
* 写入SYS_CACHE缓存
*
* @param key
* @return
*/
public
static
void
put
(
String
key
,
Object
value
)
{
put
(
SYS_CACHE
,
key
,
value
);
}
/**
* 从SYS_CACHE缓存中移除
*
* @param key
* @return
*/
public
static
void
remove
(
String
key
)
{
remove
(
SYS_CACHE
,
key
);
}
/**
* 获取缓存
*
* @param cacheName
* @param key
* @return
*/
public
static
Object
get
(
String
cacheName
,
String
key
)
{
return
getCache
(
cacheName
).
get
(
key
);
}
/**
* 获取缓存
*
* @param cacheName
* @param key
* @param defaultValue
* @return
*/
public
static
Object
get
(
String
cacheName
,
String
key
,
Object
defaultValue
)
{
Object
value
=
get
(
cacheName
,
key
);
return
value
!=
null
?
value
:
defaultValue
;
}
/**
* 写入缓存
*
* @param cacheName
* @param key
* @param value
*/
public
static
void
put
(
String
cacheName
,
String
key
,
Object
value
)
{
getCache
(
cacheName
).
put
(
key
,
value
);
}
/**
* 从缓存中移除
*
* @param cacheName
* @param key
*/
public
static
void
remove
(
String
cacheName
,
String
key
)
{
getCache
(
cacheName
).
remove
(
key
);
}
/**
* 获得一个Cache,没有则显示日志。
*
* @param cacheName
* @return
*/
private
static
Cache
<
String
,
Object
>
getCache
(
String
cacheName
)
{
Cache
<
String
,
Object
>
cache
=
cacheManager
.
getCache
(
cacheName
);
if
(
cache
==
null
)
{
throw
new
RuntimeException
(
"当前系统中没有定义“"
+
cacheName
+
"”这个缓存。"
);
}
return
cache
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/common/utils/CharsetKit.java
0 → 100644
View file @
d5ba54ba
package
com.jeespring.common.utils
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
/**
* 字符集工具类
*
* @author JeeSpring
*
*/
public
class
CharsetKit
{
/** ISO-8859-1 */
public
static
final
String
ISO_8859_1
=
"ISO-8859-1"
;
/** UTF-8 */
public
static
final
String
UTF_8
=
"UTF-8"
;
/** GBK */
public
static
final
String
GBK
=
"GBK"
;
/** ISO-8859-1 */
public
static
final
Charset
CHARSET_ISO_8859_1
=
Charset
.
forName
(
ISO_8859_1
);
/** UTF-8 */
public
static
final
Charset
CHARSET_UTF_8
=
Charset
.
forName
(
UTF_8
);
/** GBK */
public
static
final
Charset
CHARSET_GBK
=
Charset
.
forName
(
GBK
);
/**
* 转换为Charset对象
*
* @param charset 字符集,为空则返回默认字符集
* @return Charset
*/
public
static
Charset
charset
(
String
charset
)
{
return
StringUtils
.
isEmpty
(
charset
)
?
Charset
.
defaultCharset
()
:
Charset
.
forName
(
charset
);
}
/**
* 转换字符串的字符集编码
*
* @param source 字符串
* @param srcCharset 源字符集,默认ISO-8859-1
* @param destCharset 目标字符集,默认UTF-8
* @return 转换后的字符集
*/
public
static
String
convert
(
String
source
,
String
srcCharset
,
String
destCharset
)
{
return
convert
(
source
,
Charset
.
forName
(
srcCharset
),
Charset
.
forName
(
destCharset
));
}
/**
* 转换字符串的字符集编码
*
* @param source 字符串
* @param srcCharset 源字符集,默认ISO-8859-1
* @param destCharset 目标字符集,默认UTF-8
* @return 转换后的字符集
*/
public
static
String
convert
(
String
source
,
Charset
srcCharset
,
Charset
destCharset
)
{
if
(
null
==
srcCharset
)
{
srcCharset
=
StandardCharsets
.
ISO_8859_1
;
}
if
(
null
==
destCharset
)
{
srcCharset
=
StandardCharsets
.
UTF_8
;
}
if
(
StringUtils
.
isEmpty
(
source
)
||
srcCharset
.
equals
(
destCharset
))
{
return
source
;
}
return
new
String
(
source
.
getBytes
(
srcCharset
),
destCharset
);
}
/**
* @return 系统字符集编码
*/
public
static
String
systemCharset
()
{
return
Charset
.
defaultCharset
().
name
();
}
}
Prev
1
…
3
4
5
6
7
8
9
10
11
…
20
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment