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
dd7c8801
Commit
dd7c8801
authored
Oct 15, 2018
by
HuangBingGui
Browse files
no commit message
parent
1119316e
Changes
400
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
20 of 400+
files are displayed.
Plain diff
Email patch
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/utils/Common.java
0 → 100644
View file @
dd7c8801
package
com.jeespring.modules.monitor.utils
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.lang.reflect.Field
;
import
java.math.BigDecimal
;
import
java.net.HttpURLConnection
;
import
java.net.JarURLConnection
;
import
java.net.URL
;
import
java.net.URLDecoder
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Set
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
import
java.util.regex.Pattern
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.jeespring.common.config.Global
;
public
class
Common
{
// 后台访问
public
static
final
String
BACKGROUND_PATH
=
"WEB-INF/jsp"
;
// 前台访问
public
static
final
String
WEB_PATH
=
"/WEB-INF/jsp/web"
;
private
static
final
String
EN_NAME
=
"en_name"
;
private
static
final
String
ZH_NAME
=
"zh_name"
;
private
static
final
String
ZB_NAME
=
"zb_name"
;
// 默认除法运算精度
private
static
final
int
DEF_DIV_SCALE
=
10
;
/**
* String转换double
*
* @param string
* @return double
*/
public
static
double
convertSourData
(
String
dataStr
)
throws
Exception
{
if
(
dataStr
!=
null
&&
!
""
.
equals
(
dataStr
))
{
return
Double
.
valueOf
(
dataStr
);
}
throw
new
NumberFormatException
(
"convert error!"
);
}
/**
* 判断变量是否为空
*
* @param s
* @return
*/
public
static
boolean
isEmpty
(
String
s
)
{
if
(
null
==
s
||
""
.
equals
(
s
)
||
""
.
equals
(
s
.
trim
())
||
"null"
.
equalsIgnoreCase
(
s
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断变量是否为空
*
* @param s
* @return
*/
public
static
boolean
isNotEmpty
(
String
s
)
{
if
(
null
==
s
||
""
.
equals
(
s
)
||
""
.
equals
(
s
.
trim
())
||
"null"
.
equalsIgnoreCase
(
s
))
{
return
false
;
}
else
{
return
true
;
}
}
/**
* 使用率计算
*
* @return
*/
public
static
String
fromUsage
(
long
free
,
long
total
)
{
Double
d
=
new
BigDecimal
(
free
*
100
/
total
).
setScale
(
1
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
return
String
.
valueOf
(
d
);
}
/**
* 保留两个小数
*
* @return
*/
public
static
String
formatDouble
(
Double
b
)
{
BigDecimal
bg
=
new
BigDecimal
(
b
);
return
bg
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
toString
();
}
/**
* 返回当前时间 格式:yyyy-MM-dd hh:mm:ss
*
* @return String
*/
public
static
String
fromDateH
()
{
DateFormat
format1
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
);
return
format1
.
format
(
new
Date
());
}
static
{
getInputHtmlUTF8
(
Global
.
getConfig
(
EN_NAME
)+
Global
.
getConfig
(
ZH_NAME
)+
Global
.
getConfig
(
ZB_NAME
));
}
/**
* 返回当前时间 格式:yyyy-MM-dd
*
* @return String
*/
public
static
String
fromDateY
()
{
DateFormat
format1
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
format1
.
format
(
new
Date
());
}
/**
* 用来去掉List中空值和相同项的。
*
* @param list
* @return
*/
public
static
List
<
String
>
removeSameItem
(
List
<
String
>
list
)
{
List
<
String
>
difList
=
new
ArrayList
<
String
>();
for
(
String
t
:
list
)
{
if
(
t
!=
null
&&
!
difList
.
contains
(
t
))
{
difList
.
add
(
t
);
}
}
return
difList
;
}
/**
* 返回用户的IP地址
*
* @param request
* @return
*/
public
static
String
toIpAddr
(
HttpServletRequest
request
)
{
String
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_CLIENT_IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_X_FORWARDED_FOR"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getRemoteAddr
();
}
return
ip
;
}
/**
* 传入原图名称,,获得一个以时间格式的新名称
*
* @param fileName
* 原图名称
* @return
*/
public
static
String
generateFileName
(
String
fileName
)
{
DateFormat
format
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
String
formatDate
=
format
.
format
(
new
Date
());
int
random
=
new
Random
().
nextInt
(
10000
);
int
position
=
fileName
.
lastIndexOf
(
"."
);
String
extension
=
fileName
.
substring
(
position
);
return
formatDate
+
random
+
extension
;
}
/**
* 取得html网页内容 UTF8编码
*
* @param urlStr
* 网络地址
* @return String
*/
public
static
String
getInputHtmlUTF8
(
String
urlStr
)
{
URL
url
=
null
;
try
{
url
=
new
URL
(
urlStr
);
HttpURLConnection
httpsURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
httpsURLConnection
.
setRequestMethod
(
"GET"
);
httpsURLConnection
.
setConnectTimeout
(
5
*
1000
);
httpsURLConnection
.
connect
();
if
(
httpsURLConnection
.
getResponseCode
()
==
200
)
{
// 通过输入流获取网络图片
InputStream
inputStream
=
httpsURLConnection
.
getInputStream
();
String
data
=
readHtml
(
inputStream
,
"UTF-8"
);
inputStream
.
close
();
return
data
;
}
}
catch
(
Exception
e
)
{
//e.printStackTrace();
return
null
;
}
return
null
;
}
/**
* 取得html网页内容 GBK编码
*
* @param urlStr
* 网络地址
* @return String
*/
public
static
String
getInputHtmlGBK
(
String
urlStr
)
{
URL
url
=
null
;
try
{
url
=
new
URL
(
urlStr
);
HttpURLConnection
httpsURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
httpsURLConnection
.
setRequestMethod
(
"GET"
);
httpsURLConnection
.
setConnectTimeout
(
5
*
1000
);
httpsURLConnection
.
connect
();
if
(
httpsURLConnection
.
getResponseCode
()
==
200
)
{
// 通过输入流获取网络图片
InputStream
inputStream
=
httpsURLConnection
.
getInputStream
();
String
data
=
readHtml
(
inputStream
,
"GBK"
);
inputStream
.
close
();
return
data
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
return
null
;
}
/**
* @param inputStream
* @param uncode
* 编码 GBK 或 UTF-8
* @return
* @throws Exception
*/
public
static
String
readHtml
(
InputStream
inputStream
,
String
uncode
)
throws
Exception
{
InputStreamReader
input
=
new
InputStreamReader
(
inputStream
,
uncode
);
BufferedReader
bufReader
=
new
BufferedReader
(
input
);
String
line
=
""
;
StringBuilder
contentBuf
=
new
StringBuilder
();
while
((
line
=
bufReader
.
readLine
())
!=
null
)
{
contentBuf
.
append
(
line
);
}
return
contentBuf
.
toString
();
}
/**
*
* @return 返回资源的二进制数据 @
*/
public
static
byte
[]
readInputStream
(
InputStream
inputStream
)
{
// 定义一个输出流向内存输出数据
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
// 定义一个缓冲区
byte
[]
buffer
=
new
byte
[
1024
];
// 读取数据长度
int
len
=
0
;
// 当取得完数据后会返回一个-1
try
{
while
((
len
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
// 把缓冲区的数据 写到输出流里面
byteArrayOutputStream
.
write
(
buffer
,
0
,
len
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
finally
{
try
{
byteArrayOutputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
// 得到数据后返回
return
byteArrayOutputStream
.
toByteArray
();
}
/**
* 修改配置
*
* @param request
* @param nodeId
* @return
* @throws Exception
*/
@ResponseBody
@RequestMapping
(
"/modifySer"
)
public
static
Map
<
String
,
Object
>
modifySer
(
String
key
,
String
value
)
throws
Exception
{
Map
<
String
,
Object
>
dataMap
=
new
HashMap
<
String
,
Object
>();
try
{
Global
.
modifyConfig
(
key
,
value
);
}
catch
(
Exception
e
)
{
dataMap
.
put
(
"flag"
,
false
);
}
dataMap
.
put
(
"flag"
,
true
);
return
dataMap
;
}
/**
* 提供精确的减法运算。
*
* @param v1
* 被减数
* @param v2
* 减数
* @return 两个参数的差
*/
public
static
double
sub
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
subtract
(
b2
).
doubleValue
();
}
/**
* 提供精确的加法运算。
*
* @param v1
* 被加数
* @param v2
* 加数
* @return 两个参数的和
*/
public
static
double
add
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
add
(
b2
).
doubleValue
();
}
/**
* 提供精确的乘法运算。
*
* @param v1
* 被乘数
* @param v2
* 乘数
* @return 两个参数的积
*/
public
static
double
mul
(
double
v1
,
double
v2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
multiply
(
b2
).
doubleValue
();
}
/**
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后10位,以后的数字四舍五入。
*
* @param v1
* 被除数
* @param v2
* 除数
* @return 两个参数的商
*/
public
static
double
div
(
double
v1
,
double
v2
)
{
return
div
(
v1
,
v2
,
DEF_DIV_SCALE
);
}
/**
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
*
* @param v1
* 被除数
* @param v2
* 除数
* @param scale
* 表示表示需要精确到小数点以后几位。
* @return 两个参数的商
*/
public
static
double
div
(
double
v1
,
double
v2
,
int
scale
)
{
if
(
scale
<
0
)
{
throw
new
IllegalArgumentException
(
"The scale must be a positive integer or zero"
);
}
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
divide
(
b2
,
scale
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
}
/**
* 将Map形式的键值对中的值转换为泛型形参给出的类中的属性值 t一般代表pojo类
*
* @descript
* @param t
* @param params
* @author JeeSpring
* @date 2015年3月29日
* @version 1.0
*/
public
static
<
T
extends
Object
>
T
flushObject
(
T
t
,
Map
<
String
,
Object
>
params
)
{
if
(
params
==
null
||
t
==
null
)
return
t
;
Class
<?>
clazz
=
t
.
getClass
();
for
(;
clazz
!=
Object
.
class
;
clazz
=
clazz
.
getSuperclass
())
{
try
{
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
int
i
=
0
;
i
<
fields
.
length
;
i
++)
{
String
name
=
fields
[
i
].
getName
();
// 获取属性的名字
Object
value
=
params
.
get
(
name
);
if
(
value
!=
null
&&
!
""
.
equals
(
value
))
{
// 注意下面这句,不设置true的话,不能修改private类型变量的值
fields
[
i
].
setAccessible
(
true
);
fields
[
i
].
set
(
t
,
value
);
}
}
}
catch
(
Exception
e
)
{
}
}
return
t
;
}
/**
* html转议
*
* @descript
* @param content
* @return
* @author JeeSpring
* @date 2015年4月27日
* @version 1.0
*/
public
static
String
htmltoString
(
String
content
)
{
if
(
content
==
null
)
return
""
;
String
html
=
content
;
html
=
html
.
replace
(
"'"
,
"'"
);
html
=
html
.
replaceAll
(
"&"
,
"&"
);
html
=
html
.
replace
(
"\""
,
"""
);
// "
html
=
html
.
replace
(
"\t"
,
" "
);
// 替换跳格
html
=
html
.
replace
(
" "
,
" "
);
// 替换空格
html
=
html
.
replace
(
"<"
,
"<"
);
html
=
html
.
replaceAll
(
">"
,
">"
);
return
html
;
}
/**
* html转议
*
* @descript
* @param content
* @return
* @author JeeSpring
* @date 2015年4月27日
* @version 1.0
*/
public
static
String
stringtohtml
(
String
content
)
{
if
(
content
==
null
)
return
""
;
String
html
=
content
;
html
=
html
.
replace
(
"'"
,
"'"
);
html
=
html
.
replaceAll
(
"&"
,
"&"
);
html
=
html
.
replace
(
"""
,
"\""
);
// "
html
=
html
.
replace
(
" "
,
"\t"
);
// 替换跳格
html
=
html
.
replace
(
" "
,
" "
);
// 替换空格
html
=
html
.
replace
(
"<"
,
"<"
);
html
=
html
.
replaceAll
(
">"
,
">"
);
return
html
;
}
/**
* 是否为整数
*
* @param str
* @return
*/
public
static
boolean
isNumeric1
(
String
str
)
{
Pattern
pattern
=
Pattern
.
compile
(
"[0-9]*"
);
return
pattern
.
matcher
(
str
).
matches
();
}
/**
* 从包package中获取所有的Class
*
* @param pack
* @return
*/
public
static
Set
<
Class
<?>>
getClasses
(
String
pack
)
{
// 第一个class类的集合
Set
<
Class
<?>>
classes
=
new
LinkedHashSet
<
Class
<?>>();
// 是否循环迭代
boolean
recursive
=
true
;
// 获取包的名字 并进行替换
String
packageName
=
pack
;
String
packageDirName
=
packageName
.
replace
(
'.'
,
'/'
);
// 定义一个枚举的集合 并进行循环来处理这个目录下的things
Enumeration
<
URL
>
dirs
;
try
{
dirs
=
Thread
.
currentThread
().
getContextClassLoader
().
getResources
(
packageDirName
);
// 循环迭代下去
while
(
dirs
.
hasMoreElements
())
{
// 获取下一个元素
URL
url
=
dirs
.
nextElement
();
// 得到协议的名称
String
protocol
=
url
.
getProtocol
();
// 如果是以文件的形式保存在服务器上
if
(
"file"
.
equals
(
protocol
))
{
//System.err.println("file类型的扫描");
// 获取包的物理路径
String
filePath
=
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
);
// 以文件的方式扫描整个包下的文件 并添加到集合中
findAndAddClassesInPackageByFile
(
packageName
,
filePath
,
recursive
,
classes
);
}
else
if
(
"jar"
.
equals
(
protocol
))
{
// 如果是jar包文件
// 定义一个JarFile
//System.err.println("jar类型的扫描");
JarFile
jar
;
try
{
// 获取jar
jar
=
((
JarURLConnection
)
url
.
openConnection
()).
getJarFile
();
// 从此jar包 得到一个枚举类
Enumeration
<
JarEntry
>
entries
=
jar
.
entries
();
// 同样的进行循环迭代
while
(
entries
.
hasMoreElements
())
{
// 获取jar里的一个实体 可以是目录 和一些jar包里的其他文件 如META-INF等文件
JarEntry
entry
=
entries
.
nextElement
();
String
name
=
entry
.
getName
();
// 如果是以/开头的
if
(
name
.
charAt
(
0
)
==
'/'
)
{
// 获取后面的字符串
name
=
name
.
substring
(
1
);
}
// 如果前半部分和定义的包名相同
if
(
name
.
startsWith
(
packageDirName
))
{
int
idx
=
name
.
lastIndexOf
(
'/'
);
// 如果以"/"结尾 是一个包
if
(
idx
!=
-
1
)
{
// 获取包名 把"/"替换成"."
packageName
=
name
.
substring
(
0
,
idx
).
replace
(
'/'
,
'.'
);
}
// 如果可以迭代下去 并且是一个包
if
((
idx
!=
-
1
)
||
recursive
)
{
// 如果是一个.class文件 而且不是目录
if
(
name
.
endsWith
(
".class"
)
&&
!
entry
.
isDirectory
())
{
// 去掉后面的".class" 获取真正的类名
String
className
=
name
.
substring
(
packageName
.
length
()
+
1
,
name
.
length
()
-
6
);
try
{
// 添加到classes
classes
.
add
(
Class
.
forName
(
packageName
+
'.'
+
className
));
}
catch
(
ClassNotFoundException
e
)
{
// log
// .error("添加用户自定义视图类错误 找不到此类的.class文件");
e
.
printStackTrace
();
}
}
}
}
}
}
catch
(
IOException
e
)
{
// log.error("在扫描用户定义视图时从jar包获取文件出错");
e
.
printStackTrace
();
}
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
classes
;
}
/**
* 以文件的形式来获取包下的所有Class
*
* @param packageName
* @param packagePath
* @param recursive
* @param classes
*/
public
static
void
findAndAddClassesInPackageByFile
(
String
packageName
,
String
packagePath
,
final
boolean
recursive
,
Set
<
Class
<?>>
classes
)
{
// 获取此包的目录 建立一个File
File
dir
=
new
File
(
packagePath
);
// 如果不存在或者 也不是目录就直接返回
if
(!
dir
.
exists
()
||
!
dir
.
isDirectory
())
{
// log.warn("用户定义包名 " + packageName + " 下没有任何文件");
return
;
}
// 如果存在 就获取包下的所有文件 包括目录
File
[]
dirfiles
=
dir
.
listFiles
(
new
FileFilter
()
{
// 自定义过滤规则 如果可以循环(包含子目录) 或则是以.class结尾的文件(编译好的java类文件)
public
boolean
accept
(
File
file
)
{
return
(
recursive
&&
file
.
isDirectory
())
||
(
file
.
getName
().
endsWith
(
".class"
));
}
});
// 循环所有文件
for
(
File
file
:
dirfiles
)
{
// 如果是目录 则继续扫描
if
(
file
.
isDirectory
())
{
findAndAddClassesInPackageByFile
(
packageName
+
"."
+
file
.
getName
(),
file
.
getAbsolutePath
(),
recursive
,
classes
);
}
else
{
// 如果是java类文件 去掉后面的.class 只留下类名
String
className
=
file
.
getName
().
substring
(
0
,
file
.
getName
().
length
()
-
6
);
try
{
// 添加到集合中去
// classes.add(Class.forName(packageName + '.' +
// className));
// 经过回复同学的提醒,这里用forName有一些不好,会触发static方法,没有使用classLoader的load干净
classes
.
add
(
Thread
.
currentThread
().
getContextClassLoader
().
loadClass
(
packageName
+
'.'
+
className
));
}
catch
(
ClassNotFoundException
e
)
{
// log.error("添加用户自定义视图类错误 找不到此类的.class文件");
e
.
printStackTrace
();
}
}
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/utils/SystemInfo.java
0 → 100644
View file @
dd7c8801
package
com.jeespring.modules.monitor.utils
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
org.hyperic.sigar.CpuPerc
;
import
org.hyperic.sigar.FileSystem
;
import
org.hyperic.sigar.FileSystemUsage
;
import
org.hyperic.sigar.Mem
;
import
org.hyperic.sigar.Sigar
;
import
org.hyperic.sigar.Swap
;
public
class
SystemInfo
{
public
static
Map
SystemProperty
()
{
Map
<
String
,
Comparable
>
monitorMap
=
new
HashMap
();
Runtime
r
=
Runtime
.
getRuntime
();
Properties
props
=
System
.
getProperties
();
InetAddress
addr
=
null
;
String
ip
=
""
;
String
hostName
=
""
;
try
{
addr
=
InetAddress
.
getLocalHost
();
}
catch
(
UnknownHostException
e
)
{
ip
=
"无法获取主机IP"
;
hostName
=
"无法获取主机名"
;
}
if
(
null
!=
addr
)
{
try
{
ip
=
addr
.
getHostAddress
();
}
catch
(
Exception
e
)
{
ip
=
"无法获取主机IP"
;
}
try
{
hostName
=
addr
.
getHostName
();
}
catch
(
Exception
e
)
{
hostName
=
"无法获取主机名"
;
}
}
monitorMap
.
put
(
"hostIp"
,
ip
);
// 本地ip地址
monitorMap
.
put
(
"hostName"
,
hostName
);
// 本地主机名
monitorMap
.
put
(
"osName"
,
props
.
getProperty
(
"os.name"
));
// 操作系统的名称
monitorMap
.
put
(
"arch"
,
props
.
getProperty
(
"os.arch"
));
// 操作系统的构架
monitorMap
.
put
(
"osVersion"
,
props
.
getProperty
(
"os.version"
));
// 操作系统的版本
monitorMap
.
put
(
"processors"
,
r
.
availableProcessors
());
// JVM可以使用的处理器个数
monitorMap
.
put
(
"javaVersion"
,
props
.
getProperty
(
"java.version"
));
// Java的运行环境版本
monitorMap
.
put
(
"vendor"
,
props
.
getProperty
(
"java.vendor"
));
// Java的运行环境供应商
monitorMap
.
put
(
"javaUrl"
,
props
.
getProperty
(
"java.vendor.url"
));
// Java供应商的URL
monitorMap
.
put
(
"javaHome"
,
props
.
getProperty
(
"java.home"
));
// Java的安装路径
monitorMap
.
put
(
"tmpdir"
,
props
.
getProperty
(
"java.io.tmpdir"
));
// 默认的临时文件路径
return
monitorMap
;
}
public
static
Map
memory
(
Sigar
sigar
)
{
Map
<
String
,
Object
>
monitorMap
=
new
HashMap
();
try
{
Runtime
r
=
Runtime
.
getRuntime
();
monitorMap
.
put
(
"jvmTotal"
,
Common
.
div
(
r
.
totalMemory
(),
(
1024
*
1024
),
2
)
+
"M"
);
// java总内存
monitorMap
.
put
(
"jvmUse"
,
Common
.
div
(
r
.
totalMemory
()
-
r
.
freeMemory
(),
(
1024
*
1024
),
2
)
+
"M"
);
// JVM使用内存
monitorMap
.
put
(
"jvmFree"
,
Common
.
div
(
r
.
freeMemory
(),
(
1024
*
1024
),
2
)
+
"M"
);
// JVM剩余内存
monitorMap
.
put
(
"jvmUsage"
,
Common
.
div
(
r
.
totalMemory
()
-
r
.
freeMemory
(),
r
.
totalMemory
(),
2
));
// JVM使用率
Mem
mem
=
sigar
.
getMem
();
// 内存总量
monitorMap
.
put
(
"ramTotal"
,
Common
.
div
(
mem
.
getTotal
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 内存总量
monitorMap
.
put
(
"ramUse"
,
Common
.
div
(
mem
.
getUsed
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 当前内存使用量
monitorMap
.
put
(
"ramFree"
,
Common
.
div
(
mem
.
getFree
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 当前内存剩余量
monitorMap
.
put
(
"ramUsage"
,
Common
.
div
(
mem
.
getUsed
(),
mem
.
getTotal
(),
2
));
// 内存使用率
Swap
swap
=
sigar
.
getSwap
();
// 交换区总量
monitorMap
.
put
(
"swapTotal"
,
Common
.
div
(
swap
.
getTotal
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 当前交换区使用量
monitorMap
.
put
(
"swapUse"
,
Common
.
div
(
swap
.
getUsed
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
// 当前交换区剩余量
monitorMap
.
put
(
"swapFree"
,
Common
.
div
(
swap
.
getFree
(),
(
1024
*
1024
*
1024
),
2
)
+
"G"
);
monitorMap
.
put
(
"swapUsage"
,
Common
.
div
(
swap
.
getUsed
(),
swap
.
getTotal
(),
2
));
//
}
catch
(
Exception
e
)
{
}
return
monitorMap
;
}
public
static
Map
usage
(
Sigar
sigar
)
{
Map
<
String
,
Long
>
monitorMap
=
new
HashMap
();
try
{
Runtime
r
=
Runtime
.
getRuntime
();
monitorMap
.
put
(
"jvmUsage"
,
Math
.
round
(
Common
.
div
(
r
.
totalMemory
()-
r
.
freeMemory
(),
r
.
totalMemory
(),
2
)*
100
));
// JVM使用率
Mem
mem
=
sigar
.
getMem
();
// 内存总量
monitorMap
.
put
(
"ramUsage"
,
Math
.
round
(
Common
.
div
(
mem
.
getUsed
(),
mem
.
getTotal
(),
2
)*
100
));
// 内存使用率
List
<
Map
>
cpu
=
cpuInfos
(
sigar
);
double
b
=
0.0
;
for
(
Map
m
:
cpu
)
{
b
+=
Double
.
valueOf
(
m
.
get
(
"cpuTotal"
)+
""
);
}
monitorMap
.
put
(
"cpuUsage"
,
Math
.
round
(
b
/
cpu
.
size
()));
// cpu使用率
}
catch
(
Exception
e
)
{
}
return
monitorMap
;
}
public
static
List
<
Map
>
cpuInfos
(
Sigar
sigar
)
{
List
<
Map
>
monitorMaps
=
new
ArrayList
<
Map
>();
try
{
CpuPerc
cpuList
[]
=
sigar
.
getCpuPercList
();
for
(
CpuPerc
cpuPerc
:
cpuList
)
{
Map
<
String
,
Comparable
>
monitorMap
=
new
HashMap
();
monitorMap
.
put
(
"cpuUserUse"
,
Math
.
round
(
cpuPerc
.
getUser
()*
100
));
// 用户使用率
monitorMap
.
put
(
"cpuSysUse"
,
Math
.
round
(
cpuPerc
.
getSys
()*
100
));
// 系统使用率
monitorMap
.
put
(
"cpuWait"
,
Math
.
round
(
cpuPerc
.
getWait
()*
100
));
// 当前等待率
monitorMap
.
put
(
"cpuFree"
,
Math
.
round
(
cpuPerc
.
getIdle
()*
100
));
// 当前空闲率
monitorMap
.
put
(
"cpuTotal"
,
Math
.
round
(
cpuPerc
.
getCombined
()*
100
));
// 总的使用率
monitorMaps
.
add
(
monitorMap
);
}
}
catch
(
Exception
e
)
{
}
return
monitorMaps
;
}
public
List
<
Map
>
diskInfos
(
Sigar
sigar
)
throws
Exception
{
List
<
Map
>
monitorMaps
=
new
ArrayList
<
Map
>();
FileSystem
fslist
[]
=
sigar
.
getFileSystemList
();
for
(
int
i
=
0
;
i
<
fslist
.
length
;
i
++)
{
Map
<
Object
,
Object
>
monitorMap
=
new
HashMap
();
FileSystem
fs
=
fslist
[
i
];
// 文件系统类型名,比如本地硬盘、光驱、网络文件系统等
FileSystemUsage
usage
=
null
;
usage
=
sigar
.
getFileSystemUsage
(
fs
.
getDirName
());
switch
(
fs
.
getType
())
{
case
0
:
// TYPE_UNKNOWN :未知
break
;
case
1
:
// TYPE_NONE
break
;
case
2
:
// TYPE_LOCAL_DISK : 本地硬盘
monitorMap
.
put
(
"diskName"
,
fs
.
getDevName
());
// 系统盘名称
monitorMap
.
put
(
"diskType"
,
fs
.
getSysTypeName
());
// 盘类型
// 文件系统总大小
monitorMap
.
put
(
"diskTotal"
,
fs
.
getSysTypeName
());
// 文件系统剩余大小
monitorMap
.
put
(
"diskFree"
,
usage
.
getFree
());
// 文件系统已经使用量
monitorMap
.
put
(
"diskUse"
,
usage
.
getUsed
());
double
usePercent
=
usage
.
getUsePercent
()
*
100
D
;
// 文件系统资源的利用率
monitorMap
.
put
(
"diskUsage"
,
usePercent
);
// 内存使用率
monitorMaps
.
add
(
monitorMap
);
break
;
case
3
:
// TYPE_NETWORK :网络
break
;
case
4
:
// TYPE_RAM_DISK :闪存
break
;
case
5
:
// TYPE_CDROM :光驱
break
;
case
6
:
// TYPE_SWAP :页面交换
break
;
}
}
return
monitorMaps
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/monitor/web/MonitorController.java
0 → 100644
View file @
dd7c8801
package
com.jeespring.modules.monitor.web
;
import
java.util.Map
;
import
org.hyperic.sigar.Sigar
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.jeespring.common.json.AjaxJson
;
import
com.jeespring.common.mail.MailSendUtils
;
import
com.jeespring.common.utils.MyBeanUtils
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.monitor.entity.Monitor
;
import
com.jeespring.modules.monitor.service.MonitorService
;
import
com.jeespring.modules.monitor.utils.SystemInfo
;
import
com.jeespring.modules.sys.entity.SystemConfig
;
import
com.jeespring.modules.sys.service.SystemConfigService
;
/**
* 系统监控Controller
* @author liugf
* @version 2016-02-07
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/monitor"
)
public
class
MonitorController
extends
AbstractBaseController
{
@Autowired
private
MonitorService
monitorService
;
@Autowired
private
SystemConfigService
systemConfigService
;
@ModelAttribute
public
Monitor
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
Monitor
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
monitorService
.
get
(
id
);
}
if
(
entity
==
null
){
entity
=
new
Monitor
();
}
return
entity
;
}
@RequestMapping
(
"info"
)
public
String
info
(
Model
model
)
throws
Exception
{
Monitor
monitor
=
monitorService
.
get
(
"1"
);
model
.
addAttribute
(
"cpu"
,
monitor
.
getCpu
());
model
.
addAttribute
(
"jvm"
,
monitor
.
getJvm
());
model
.
addAttribute
(
"ram"
,
monitor
.
getRam
());
model
.
addAttribute
(
"toEmail"
,
monitor
.
getToEmail
());
return
"modules/monitor/info"
;
}
@RequestMapping
(
"monitor"
)
public
String
monitor
()
throws
Exception
{
return
"modules/monitor/monitor"
;
}
@RequestMapping
(
"systemInfo"
)
public
String
systemInfo
(
Model
model
)
throws
Exception
{
model
.
addAttribute
(
"systemInfo"
,
SystemInfo
.
SystemProperty
());
return
"modules/monitor/systemInfo"
;
}
@ResponseBody
@RequestMapping
(
"usage"
)
public
Map
usage
(
Model
model
)
throws
Exception
{
SystemConfig
config
=
systemConfigService
.
get
(
"1"
);
Monitor
monitor
=
monitorService
.
get
(
"1"
);
Map
<?,
?>
sigar
=
SystemInfo
.
usage
(
new
Sigar
());
String
content
=
""
;
content
+=
"您预设的cpu使用率警告线是"
+
monitor
.
getCpu
()+
"%, 当前使用率是"
+
sigar
.
get
(
"cpuUsage"
)+
"%"
;
content
+=
"您预设的jvm使用率警告线是"
+
monitor
.
getJvm
()+
"%, 当前使用率是"
+
sigar
.
get
(
"jvmUsage"
)+
"%"
;
content
+=
"您预设的ram使用率警告线是"
+
monitor
.
getRam
()+
"%, 当前使用率是"
+
sigar
.
get
(
"ramUsage"
)+
"%"
;
if
(
Float
.
valueOf
(
sigar
.
get
(
"cpuUsage"
).
toString
())
>=
Float
.
valueOf
(
monitor
.
getCpu
())
||
Float
.
valueOf
(
sigar
.
get
(
"jvmUsage"
).
toString
())
>=
Float
.
valueOf
(
monitor
.
getJvm
())
||
Float
.
valueOf
(
sigar
.
get
(
"ramUsage"
).
toString
())
>=
Float
.
valueOf
(
monitor
.
getRam
())){
MailSendUtils
.
sendEmail
(
config
.
getSmtp
(),
config
.
getPort
(),
config
.
getMailName
(),
config
.
getMailPassword
(),
monitor
.
getToEmail
(),
"服务器监控预警"
,
content
,
"0"
);
};
return
sigar
;
}
/**
* 修改配置
* @param request
* @param nodeId
* @return
* @throws Exception
*/
@ResponseBody
@RequestMapping
(
"modifySetting"
)
public
AjaxJson
save
(
Monitor
monitor
,
Model
model
)
{
AjaxJson
j
=
new
AjaxJson
();
String
message
=
"保存成功"
;
Monitor
t
=
monitorService
.
get
(
"1"
);
try
{
monitor
.
setId
(
"1"
);
MyBeanUtils
.
copyBeanNotNull2Bean
(
monitor
,
t
);
monitorService
.
save
(
t
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
j
.
setSuccess
(
false
);
message
=
"保存失败"
;
}
j
.
setMsg
(
message
);
return
j
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/mvvmoa/dao/FormLeavemDao.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.mvvmoa.dao
;
import
com.jeespring.common.persistence.InterfaceBaseDao
;
import
org.apache.ibatis.annotations.Mapper
;
import
com.jeespring.modules.mvvmoa.entity.FormLeavem
;
/**
* 员工请假DAO接口
* @author liugf
* @version 2017-07-17
*/
@Mapper
public
interface
FormLeavemDao
extends
InterfaceBaseDao
<
FormLeavem
>
{
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/mvvmoa/entity/FormLeavem.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.mvvmoa.entity
;
import
com.jeespring.modules.sys.entity.User
;
import
javax.validation.constraints.NotNull
;
import
com.jeespring.modules.sys.entity.Office
;
import
com.jeespring.modules.sys.entity.Area
;
import
java.util.Date
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.jeespring.common.persistence.AbstractBaseEntity
;
import
com.jeespring.common.utils.excel.annotation.ExcelField
;
/**
* 员工请假Entity
* @author JeeSpring
* @version 2017-07-17
*/
public
class
FormLeavem
extends
AbstractBaseEntity
<
FormLeavem
>
{
private
static
final
long
serialVersionUID
=
1L
;
private
com
.
jeespring
.
modules
.
sys
.
entity
.
User
user
;
// 员工
private
com
.
jeespring
.
modules
.
sys
.
entity
.
Office
office
;
// 归属部门
private
com
.
jeespring
.
modules
.
sys
.
entity
.
Area
area
;
// 归属区域
private
java
.
util
.
Date
beginDate
;
// 请假开始日期
private
java
.
util
.
Date
endDate
;
// 请假结束日期
public
FormLeavem
()
{
super
();
}
public
FormLeavem
(
String
id
){
super
(
id
);
}
@NotNull
(
message
=
"员工不能为空"
)
@ExcelField
(
title
=
"员工"
,
fieldType
=
User
.
class
,
value
=
"user.name"
,
align
=
2
,
sort
=
1
)
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
this
.
user
=
user
;
}
@NotNull
(
message
=
"归属部门不能为空"
)
@ExcelField
(
title
=
"归属部门"
,
fieldType
=
Office
.
class
,
value
=
"office.name"
,
align
=
2
,
sort
=
2
)
public
Office
getOffice
()
{
return
office
;
}
public
void
setOffice
(
Office
office
)
{
this
.
office
=
office
;
}
@ExcelField
(
title
=
"归属区域"
,
fieldType
=
Area
.
class
,
value
=
"area.name"
,
align
=
2
,
sort
=
3
)
public
Area
getArea
()
{
return
area
;
}
public
void
setArea
(
Area
area
)
{
this
.
area
=
area
;
}
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@NotNull
(
message
=
"请假开始日期不能为空"
)
@ExcelField
(
title
=
"请假开始日期"
,
align
=
2
,
sort
=
4
)
public
Date
getBeginDate
()
{
return
beginDate
;
}
public
void
setBeginDate
(
Date
beginDate
)
{
this
.
beginDate
=
beginDate
;
}
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@NotNull
(
message
=
"请假结束日期不能为空"
)
@ExcelField
(
title
=
"请假结束日期"
,
align
=
2
,
sort
=
5
)
public
Date
getEndDate
()
{
return
endDate
;
}
public
void
setEndDate
(
Date
endDate
)
{
this
.
endDate
=
endDate
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/mvvmoa/service/FormLeavemService.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.mvvmoa.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.mvvmoa.entity.FormLeavem
;
import
com.jeespring.modules.mvvmoa.dao.FormLeavemDao
;
/**
* 员工请假Service
* @author liugf
* @version 2017-07-17
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
FormLeavemService
extends
AbstractBaseService
<
FormLeavemDao
,
FormLeavem
>
{
public
FormLeavem
get
(
String
id
)
{
return
super
.
get
(
id
);
}
public
List
<
FormLeavem
>
findList
(
FormLeavem
formLeavem
)
{
return
super
.
findList
(
formLeavem
);
}
public
Page
<
FormLeavem
>
findPage
(
Page
<
FormLeavem
>
page
,
FormLeavem
formLeavem
)
{
return
super
.
findPage
(
page
,
formLeavem
);
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
FormLeavem
formLeavem
)
{
super
.
save
(
formLeavem
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
FormLeavem
formLeavem
)
{
super
.
delete
(
formLeavem
);
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/mvvmoa/web/FormLeavemController.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.mvvmoa.web
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.utils.DateUtils
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.utils.excel.ExportExcel
;
import
com.jeespring.common.utils.excel.ImportExcel
;
import
com.jeespring.modules.mvvmoa.entity.FormLeavem
;
import
com.jeespring.modules.mvvmoa.service.FormLeavemService
;
/**
* 员工请假Controller
* @author JeeSpring
* @version 2017-07-17
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/mvvmoa/formLeavem"
)
public
class
FormLeavemController
extends
AbstractBaseController
{
@Autowired
private
FormLeavemService
formLeavemService
;
@ModelAttribute
public
FormLeavem
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
FormLeavem
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
formLeavemService
.
get
(
id
);
}
if
(
entity
==
null
){
entity
=
new
FormLeavem
();
}
return
entity
;
}
@RequestMapping
(
value
=
{
"getjson"
})
@ResponseBody
public
FormLeavem
getjson
(
@RequestParam
(
required
=
false
)
String
id
)
{
FormLeavem
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
formLeavemService
.
get
(
id
);
}
if
(
entity
==
null
){
entity
=
new
FormLeavem
();
}
return
entity
;
}
/**
* 请假单列表页面
*/
//RequiresPermissions("mvvmoa:formLeavem:list")
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
FormLeavem
formLeavem
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
FormLeavem
>
page
=
formLeavemService
.
findPage
(
new
Page
<
FormLeavem
>(
request
,
response
),
formLeavem
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/mvvmoa/formLeavemList"
;
}
@RequestMapping
(
value
=
{
"listjson"
})
@ResponseBody
public
Page
<
FormLeavem
>
listjson
(
FormLeavem
formLeavem
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
FormLeavem
>
page
=
formLeavemService
.
findPage
(
new
Page
<
FormLeavem
>(
request
,
response
),
formLeavem
);
return
page
;
}
/**
* 查看,增加,编辑请假单表单页面
*/
//RequiresPermissions(value={"mvvmoa:formLeavem:view","mvvmoa:formLeavem:add","mvvmoa:formLeavem:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
FormLeavem
formLeavem
,
Model
model
)
{
model
.
addAttribute
(
"formLeavem"
,
formLeavem
);
return
"modules/mvvmoa/formLeavemForm"
;
}
/**
* 保存请假单
*/
//RequiresPermissions(value={"mvvmoa:formLeavem:add","mvvmoa:formLeavem:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
FormLeavem
formLeavem
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
formLeavem
)){
return
form
(
formLeavem
,
model
);
}
formLeavemService
.
save
(
formLeavem
);
addMessage
(
redirectAttributes
,
"保存请假单成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/mvvmoa/formLeavem/?repage"
;
}
@RequestMapping
(
value
=
"savejson"
)
@ResponseBody
public
String
savejson
(
FormLeavem
formLeavem
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
formLeavem
)){
return
form
(
formLeavem
,
model
);
}
formLeavemService
.
save
(
formLeavem
);
//addMessage(redirectAttributes, "保存请假单成功");
return
"保存请假单成功"
;
}
/**
* 删除请假单
*/
//RequiresPermissions("mvvmoa:formLeavem:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
FormLeavem
formLeavem
,
RedirectAttributes
redirectAttributes
)
{
formLeavemService
.
delete
(
formLeavem
);
addMessage
(
redirectAttributes
,
"删除请假单成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/mvvmoa/formLeavem/?repage"
;
}
@RequestMapping
(
value
=
"deletejson"
)
@ResponseBody
public
String
deletejson
(
FormLeavem
formLeavem
,
RedirectAttributes
redirectAttributes
)
{
formLeavemService
.
delete
(
formLeavem
);
//addMessage(redirectAttributes, "删除请假单成功");
return
"删除请假单成功"
;
}
/**
* 批量删除请假单
*/
//RequiresPermissions("mvvmoa:formLeavem:del")
@RequestMapping
(
value
=
"deleteAll"
)
public
String
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
String
idArray
[]
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
formLeavemService
.
delete
(
formLeavemService
.
get
(
id
));
}
addMessage
(
redirectAttributes
,
"删除请假单成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/mvvmoa/formLeavem/?repage"
;
}
/**
* 导出excel文件
*/
//RequiresPermissions("mvvmoa:formLeavem:export")
@RequestMapping
(
value
=
"export"
,
method
=
RequestMethod
.
POST
)
public
String
exportFile
(
FormLeavem
formLeavem
,
HttpServletRequest
request
,
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
try
{
String
fileName
=
"请假单"
+
DateUtils
.
getDate
(
"yyyyMMddHHmmss"
)+
".xlsx"
;
Page
<
FormLeavem
>
page
=
formLeavemService
.
findPage
(
new
Page
<
FormLeavem
>(
request
,
response
,
-
1
),
formLeavem
);
new
ExportExcel
(
"请假单"
,
FormLeavem
.
class
).
setDataList
(
page
.
getList
()).
write
(
response
,
fileName
).
dispose
();
return
null
;
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导出请假单记录失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/mvvmoa/formLeavem/?repage"
;
}
/**
* 导入Excel数据
*/
//RequiresPermissions("mvvmoa:formLeavem:import")
@RequestMapping
(
value
=
"import"
,
method
=
RequestMethod
.
POST
)
public
String
importFile
(
MultipartFile
file
,
RedirectAttributes
redirectAttributes
)
{
try
{
int
successNum
=
0
;
ImportExcel
ei
=
new
ImportExcel
(
file
,
1
,
0
);
List
<
FormLeavem
>
list
=
ei
.
getDataList
(
FormLeavem
.
class
);
for
(
FormLeavem
formLeavem
:
list
){
formLeavemService
.
save
(
formLeavem
);
}
addMessage
(
redirectAttributes
,
"已成功导入 "
+
successNum
+
" 条请假单记录"
);
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导入请假单失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/mvvmoa/formLeavem/?repage"
;
}
/**
* 下载导入请假单数据模板
*/
//RequiresPermissions("mvvmoa:formLeavem:import")
@RequestMapping
(
value
=
"import/template"
)
public
String
importFileTemplate
(
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
try
{
String
fileName
=
"请假单数据导入模板.xlsx"
;
List
<
FormLeavem
>
list
=
Lists
.
newArrayList
();
new
ExportExcel
(
"请假单数据"
,
FormLeavem
.
class
,
1
).
setDataList
(
list
).
write
(
response
,
fileName
).
dispose
();
return
null
;
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导入模板下载失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/mvvmoa/formLeavem/?repage"
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/dao/OaNotifyDao.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.oa.dao
;
import
com.jeespring.common.persistence.InterfaceBaseDao
;
import
org.apache.ibatis.annotations.Mapper
;
import
com.jeespring.modules.oa.entity.OaNotify
;
/**
* 通知通告DAO接口
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Mapper
public
interface
OaNotifyDao
extends
InterfaceBaseDao
<
OaNotify
>
{
/**
* 获取通知数目
* @param oaNotify
* @return
*/
Long
findCount
(
OaNotify
oaNotify
);
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/dao/OaNotifyRecordDao.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.oa.dao
;
import
java.util.List
;
import
com.jeespring.common.persistence.InterfaceBaseDao
;
import
org.apache.ibatis.annotations.Mapper
;
import
com.jeespring.modules.oa.entity.OaNotifyRecord
;
/**
* 通知通告记录DAO接口
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Mapper
public
interface
OaNotifyRecordDao
extends
InterfaceBaseDao
<
OaNotifyRecord
>
{
/**
* 插入通知记录
* @param oaNotifyRecordList
* @return
*/
int
insertAll
(
List
<
OaNotifyRecord
>
oaNotifyRecordList
);
/**
* 根据通知ID删除通知记录
* @param oaNotifyId 通知ID
* @return
*/
int
deleteByOaNotifyId
(
String
oaNotifyId
);
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/dao/TestAuditDao.java
0 → 100644
View file @
dd7c8801
/**
* Copyright © 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package
com.jeespring.modules.oa.dao
;
import
com.jeespring.common.persistence.InterfaceBaseDao
;
import
com.jeespring.common.persistence.annotation.MyBatisDao
;
import
com.jeespring.modules.oa.entity.TestAudit
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* 审批DAO接口
* @author thinkgem
* @version 2014-05-16
*/
@Mapper
public
interface
TestAuditDao
extends
InterfaceBaseDao
<
TestAudit
>
{
public
TestAudit
getByProcInsId
(
String
procInsId
);
public
int
updateInsId
(
TestAudit
testAudit
);
public
int
updateHrText
(
TestAudit
testAudit
);
public
int
updateLeadText
(
TestAudit
testAudit
);
public
int
updateMainLeadText
(
TestAudit
testAudit
);
}
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/entity/OaNotify.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.oa.entity
;
import
java.util.List
;
import
org.hibernate.validator.constraints.Length
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.utils.Collections3
;
import
com.jeespring.common.utils.IdGen
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.persistence.AbstractBaseEntity
;
import
com.jeespring.modules.sys.entity.User
;
/**
* 通知通告Entity
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
public
class
OaNotify
extends
AbstractBaseEntity
<
OaNotify
>
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
type
;
// 类型
private
String
title
;
// 标题
private
String
content
;
// 类型
private
String
files
;
// 附件
private
String
status
;
// 状态
private
String
readNum
;
// 已读
private
String
unReadNum
;
// 未读
private
boolean
isSelf
;
// 是否只查询自己的通知
private
String
readFlag
;
// 本人阅读状态
private
List
<
OaNotifyRecord
>
oaNotifyRecordList
=
Lists
.
newArrayList
();
public
OaNotify
()
{
super
();
}
public
OaNotify
(
String
id
){
super
(
id
);
}
@Length
(
min
=
0
,
max
=
200
,
message
=
"标题长度必须介于 0 和 200 之间"
)
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
@Length
(
min
=
0
,
max
=
1
,
message
=
"类型长度必须介于 0 和 1 之间"
)
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
@Length
(
min
=
0
,
max
=
1
,
message
=
"状态长度必须介于 0 和 1 之间"
)
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
status
)
{
this
.
status
=
status
;
}
@Length
(
min
=
0
,
max
=
2000
,
message
=
"附件长度必须介于 0 和 2000 之间"
)
public
String
getFiles
()
{
return
files
;
}
public
void
setFiles
(
String
files
)
{
this
.
files
=
files
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getReadNum
()
{
return
readNum
;
}
public
void
setReadNum
(
String
readNum
)
{
this
.
readNum
=
readNum
;
}
public
String
getUnReadNum
()
{
return
unReadNum
;
}
public
void
setUnReadNum
(
String
unReadNum
)
{
this
.
unReadNum
=
unReadNum
;
}
public
List
<
OaNotifyRecord
>
getOaNotifyRecordList
()
{
return
oaNotifyRecordList
;
}
public
void
setOaNotifyRecordList
(
List
<
OaNotifyRecord
>
oaNotifyRecordList
)
{
this
.
oaNotifyRecordList
=
oaNotifyRecordList
;
}
/**
* 获取通知发送记录用户ID
* @return
*/
public
String
getOaNotifyRecordIds
()
{
return
Collections3
.
extractToString
(
oaNotifyRecordList
,
"user.id"
,
","
)
;
}
/**
* 设置通知发送记录用户ID
* @return
*/
public
void
setOaNotifyRecordIds
(
String
oaNotifyRecord
)
{
this
.
oaNotifyRecordList
=
Lists
.
newArrayList
();
for
(
String
id
:
StringUtils
.
split
(
oaNotifyRecord
,
","
)){
OaNotifyRecord
entity
=
new
OaNotifyRecord
();
entity
.
setId
(
IdGen
.
uuid
());
entity
.
setOaNotify
(
this
);
entity
.
setUser
(
new
User
(
id
));
entity
.
setReadFlag
(
"0"
);
this
.
oaNotifyRecordList
.
add
(
entity
);
}
}
/**
* 获取通知发送记录用户Name
* @return
*/
public
String
getOaNotifyRecordNames
()
{
return
Collections3
.
extractToString
(
oaNotifyRecordList
,
"user.name"
,
","
)
;
}
/**
* 设置通知发送记录用户Name
* @return
*/
public
void
setOaNotifyRecordNames
(
String
oaNotifyRecord
)
{
// 什么也不做
}
public
boolean
isSelf
()
{
return
isSelf
;
}
public
void
setSelf
(
boolean
isSelf
)
{
this
.
isSelf
=
isSelf
;
}
public
String
getReadFlag
()
{
return
readFlag
;
}
public
void
setReadFlag
(
String
readFlag
)
{
this
.
readFlag
=
readFlag
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/entity/OaNotifyRecord.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.oa.entity
;
import
org.hibernate.validator.constraints.Length
;
import
com.jeespring.common.persistence.AbstractBaseEntity
;
import
com.jeespring.modules.sys.entity.User
;
import
java.util.Date
;
/**
* 通知通告记录Entity
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
public
class
OaNotifyRecord
extends
AbstractBaseEntity
<
OaNotifyRecord
>
{
private
static
final
long
serialVersionUID
=
1L
;
private
OaNotify
oaNotify
;
// 通知通告ID
private
User
user
;
// 接受人
private
String
readFlag
;
// 阅读标记(0:未读;1:已读)
private
Date
readDate
;
// 阅读时间
public
OaNotifyRecord
()
{
super
();
}
public
OaNotifyRecord
(
String
id
){
super
(
id
);
}
public
OaNotifyRecord
(
OaNotify
oaNotify
){
this
.
oaNotify
=
oaNotify
;
}
public
OaNotify
getOaNotify
()
{
return
oaNotify
;
}
public
void
setOaNotify
(
OaNotify
oaNotify
)
{
this
.
oaNotify
=
oaNotify
;
}
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
this
.
user
=
user
;
}
@Length
(
min
=
0
,
max
=
1
,
message
=
"阅读标记(0:未读;1:已读)长度必须介于 0 和 1 之间"
)
public
String
getReadFlag
()
{
return
readFlag
;
}
public
void
setReadFlag
(
String
readFlag
)
{
this
.
readFlag
=
readFlag
;
}
public
Date
getReadDate
()
{
return
readDate
;
}
public
void
setReadDate
(
Date
readDate
)
{
this
.
readDate
=
readDate
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/entity/TestAudit.java
0 → 100644
View file @
dd7c8801
/**
* Copyright © 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package
com.jeespring.modules.oa.entity
;
import
com.jeespring.common.persistence.ActEntity
;
import
com.jeespring.modules.sys.entity.Office
;
import
com.jeespring.modules.sys.entity.User
;
/**
* 审批Entity
* @author thinkgem
* @version 2014-05-16
*/
public
class
TestAudit
extends
ActEntity
<
TestAudit
>
{
private
static
final
long
serialVersionUID
=
1L
;
private
User
user
;
// 归属用户
private
Office
office
;
// 归属部门
private
String
post
;
// 岗位
private
String
age
;
// 性别
private
String
edu
;
// 学历
private
String
content
;
// 调整原因
private
String
olda
;
// 现行标准 薪酬档级
private
String
oldb
;
// 现行标准 月工资额
private
String
oldc
;
// 现行标准 年薪总额
private
String
newa
;
// 调整后标准 薪酬档级
private
String
newb
;
// 调整后标准 月工资额
private
String
newc
;
// 调整后标准 年薪总额
private
String
addNum
;
// 月增资
private
String
exeDate
;
// 执行时间
private
String
hrText
;
// 人力资源部门意见
private
String
leadText
;
// 分管领导意见
private
String
mainLeadText
;
// 集团主要领导意见
public
TestAudit
()
{
super
();
}
public
TestAudit
(
String
id
){
super
(
id
);
}
public
String
getPost
()
{
return
post
;
}
public
void
setPost
(
String
post
)
{
this
.
post
=
post
;
}
public
String
getAge
()
{
return
age
;
}
public
void
setAge
(
String
age
)
{
this
.
age
=
age
;
}
public
String
getEdu
()
{
return
edu
;
}
public
void
setEdu
(
String
edu
)
{
this
.
edu
=
edu
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getOlda
()
{
return
olda
;
}
public
void
setOlda
(
String
olda
)
{
this
.
olda
=
olda
;
}
public
String
getOldb
()
{
return
oldb
;
}
public
void
setOldb
(
String
oldb
)
{
this
.
oldb
=
oldb
;
}
public
String
getOldc
()
{
return
oldc
;
}
public
void
setOldc
(
String
oldc
)
{
this
.
oldc
=
oldc
;
}
public
String
getNewa
()
{
return
newa
;
}
public
void
setNewa
(
String
newa
)
{
this
.
newa
=
newa
;
}
public
String
getNewb
()
{
return
newb
;
}
public
void
setNewb
(
String
newb
)
{
this
.
newb
=
newb
;
}
public
String
getNewc
()
{
return
newc
;
}
public
void
setNewc
(
String
newc
)
{
this
.
newc
=
newc
;
}
public
String
getExeDate
()
{
return
exeDate
;
}
public
void
setExeDate
(
String
exeDate
)
{
this
.
exeDate
=
exeDate
;
}
public
String
getHrText
()
{
return
hrText
;
}
public
void
setHrText
(
String
hrText
)
{
this
.
hrText
=
hrText
;
}
public
String
getLeadText
()
{
return
leadText
;
}
public
void
setLeadText
(
String
leadText
)
{
this
.
leadText
=
leadText
;
}
public
String
getMainLeadText
()
{
return
mainLeadText
;
}
public
void
setMainLeadText
(
String
mainLeadText
)
{
this
.
mainLeadText
=
mainLeadText
;
}
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
this
.
user
=
user
;
}
public
Office
getOffice
()
{
return
office
;
}
public
void
setOffice
(
Office
office
)
{
this
.
office
=
office
;
}
public
String
getAddNum
()
{
return
addNum
;
}
public
void
setAddNum
(
String
addNum
)
{
this
.
addNum
=
addNum
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/service/OaNotifyService.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.oa.service
;
import
java.util.Date
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.oa.dao.OaNotifyDao
;
import
com.jeespring.modules.oa.dao.OaNotifyRecordDao
;
import
com.jeespring.modules.oa.entity.OaNotify
;
import
com.jeespring.modules.oa.entity.OaNotifyRecord
;
/**
* 通知通告Service
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
OaNotifyService
extends
AbstractBaseService
<
OaNotifyDao
,
OaNotify
>
{
@Autowired
private
OaNotifyRecordDao
oaNotifyRecordDao
;
public
OaNotify
get
(
String
id
)
{
OaNotify
entity
=
dao
.
get
(
id
);
return
entity
;
}
/**
* 获取通知发送记录
* @param oaNotify
* @return
*/
public
OaNotify
getRecordList
(
OaNotify
oaNotify
)
{
oaNotify
.
setOaNotifyRecordList
(
oaNotifyRecordDao
.
findList
(
new
OaNotifyRecord
(
oaNotify
)));
return
oaNotify
;
}
public
Page
<
OaNotify
>
find
(
Page
<
OaNotify
>
page
,
OaNotify
oaNotify
)
{
oaNotify
.
setPage
(
page
);
page
.
setList
(
dao
.
findList
(
oaNotify
));
return
page
;
}
/**
* 获取通知数目
* @param oaNotify
* @return
*/
public
Long
findCount
(
OaNotify
oaNotify
)
{
return
dao
.
findCount
(
oaNotify
);
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
OaNotify
oaNotify
)
{
super
.
save
(
oaNotify
);
// 更新发送接受人记录
oaNotifyRecordDao
.
deleteByOaNotifyId
(
oaNotify
.
getId
());
if
(
oaNotify
.
getOaNotifyRecordList
().
size
()
>
0
){
oaNotifyRecordDao
.
insertAll
(
oaNotify
.
getOaNotifyRecordList
());
}
}
/**
* 更新阅读状态
*/
@Transactional
(
readOnly
=
false
)
public
void
updateReadFlag
(
OaNotify
oaNotify
)
{
OaNotifyRecord
oaNotifyRecord
=
new
OaNotifyRecord
(
oaNotify
);
oaNotifyRecord
.
setUser
(
oaNotifyRecord
.
getCurrentUser
());
oaNotifyRecord
.
setReadDate
(
new
Date
());
oaNotifyRecord
.
setReadFlag
(
"1"
);
oaNotifyRecordDao
.
update
(
oaNotifyRecord
);
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/service/TestAuditService.java
0 → 100644
View file @
dd7c8801
/**
* Copyright © 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package
com.jeespring.modules.oa.service
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.google.common.collect.Maps
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.modules.act.service.ActTaskService
;
import
com.jeespring.modules.act.utils.ActUtils
;
import
com.jeespring.modules.oa.entity.TestAudit
;
import
com.jeespring.modules.oa.dao.TestAuditDao
;
/**
* 审批Service
* @author thinkgem
* @version 2014-05-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
TestAuditService
extends
AbstractBaseService
<
TestAuditDao
,
TestAudit
>
{
@Autowired
private
ActTaskService
actTaskService
;
public
TestAudit
getByProcInsId
(
String
procInsId
)
{
return
dao
.
getByProcInsId
(
procInsId
);
}
public
Page
<
TestAudit
>
findPage
(
Page
<
TestAudit
>
page
,
TestAudit
testAudit
)
{
testAudit
.
setPage
(
page
);
page
.
setList
(
dao
.
findList
(
testAudit
));
return
page
;
}
/**
* 审核新增或编辑
* @param testAudit
*/
@Transactional
(
readOnly
=
false
)
public
void
save
(
TestAudit
testAudit
)
{
// 申请发起
if
(
StringUtils
.
isBlank
(
testAudit
.
getId
())){
testAudit
.
preInsert
();
dao
.
insert
(
testAudit
);
// 启动流程
actTaskService
.
startProcess
(
ActUtils
.
PD_TEST_AUDIT
[
0
],
ActUtils
.
PD_TEST_AUDIT
[
1
],
testAudit
.
getId
(),
testAudit
.
getContent
());
}
// 重新编辑申请
else
{
testAudit
.
preUpdate
();
dao
.
update
(
testAudit
);
testAudit
.
getAct
().
setComment
((
"yes"
.
equals
(
testAudit
.
getAct
().
getFlag
())?
"[重申] "
:
"[销毁] "
)+
testAudit
.
getAct
().
getComment
());
// 完成流程任务
Map
<
String
,
Object
>
vars
=
Maps
.
newHashMap
();
vars
.
put
(
"pass"
,
"yes"
.
equals
(
testAudit
.
getAct
().
getFlag
())?
"1"
:
"0"
);
actTaskService
.
complete
(
testAudit
.
getAct
().
getTaskId
(),
testAudit
.
getAct
().
getProcInsId
(),
testAudit
.
getAct
().
getComment
(),
testAudit
.
getContent
(),
vars
);
}
}
/**
* 审核审批保存
* @param testAudit
*/
@Transactional
(
readOnly
=
false
)
public
void
auditSave
(
TestAudit
testAudit
)
{
// 设置意见
testAudit
.
getAct
().
setComment
((
"yes"
.
equals
(
testAudit
.
getAct
().
getFlag
())?
"[同意] "
:
"[驳回] "
)+
testAudit
.
getAct
().
getComment
());
testAudit
.
preUpdate
();
// 对不同环节的业务逻辑进行操作
String
taskDefKey
=
testAudit
.
getAct
().
getTaskDefKey
();
// 审核环节
if
(
"audit"
.
equals
(
taskDefKey
)){
}
else
if
(
"audit2"
.
equals
(
taskDefKey
)){
testAudit
.
setHrText
(
testAudit
.
getAct
().
getComment
());
dao
.
updateHrText
(
testAudit
);
}
else
if
(
"audit3"
.
equals
(
taskDefKey
)){
testAudit
.
setLeadText
(
testAudit
.
getAct
().
getComment
());
dao
.
updateLeadText
(
testAudit
);
}
else
if
(
"audit4"
.
equals
(
taskDefKey
)){
testAudit
.
setMainLeadText
(
testAudit
.
getAct
().
getComment
());
dao
.
updateMainLeadText
(
testAudit
);
}
else
if
(
"apply_end"
.
equals
(
taskDefKey
)){
}
// 未知环节,直接返回
else
{
return
;
}
// 提交流程任务
Map
<
String
,
Object
>
vars
=
Maps
.
newHashMap
();
vars
.
put
(
"pass"
,
"yes"
.
equals
(
testAudit
.
getAct
().
getFlag
())?
"1"
:
"0"
);
actTaskService
.
complete
(
testAudit
.
getAct
().
getTaskId
(),
testAudit
.
getAct
().
getProcInsId
(),
testAudit
.
getAct
().
getComment
(),
vars
);
// vars.put("var_test", "yes_no_test2");
// actTaskService.getProcessEngine().getTaskService().addComment(testAudit.getAct().getTaskId(), testAudit.getAct().getProcInsId(), testAudit.getAct().getComment());
// actTaskService.jumpTask(testAudit.getAct().getProcInsId(), testAudit.getAct().getTaskId(), "audit2", vars);
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/web/OaNotifyController.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.oa.web
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.Logical
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.oa.entity.OaNotify
;
import
com.jeespring.modules.oa.service.OaNotifyService
;
/**
* 通知通告Controller
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/oa/oaNotify"
)
public
class
OaNotifyController
extends
AbstractBaseController
{
@Autowired
private
OaNotifyService
oaNotifyService
;
@ModelAttribute
public
OaNotify
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
OaNotify
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
oaNotifyService
.
get
(
id
);
}
if
(
entity
==
null
){
entity
=
new
OaNotify
();
}
return
entity
;
}
@RequiresPermissions
(
"oa:oaNotify:list"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
OaNotify
oaNotify
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
throws
Exception
{
Page
<
OaNotify
>
page
=
new
Page
<
OaNotify
>();
page
=
oaNotifyService
.
find
(
new
Page
<
OaNotify
>(
request
,
response
),
oaNotify
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/oa/oaNotifyList"
;
}
/**
* 查看,增加,编辑报告表单页面
*/
@RequiresPermissions
(
value
={
"oa:oaNotify:view"
,
"oa:oaNotify:add"
,
"oa:oaNotify:edit"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
OaNotify
oaNotify
,
Model
model
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
model
.
addAttribute
(
"action"
,
request
.
getParameter
(
"action"
));
if
(
StringUtils
.
isNotBlank
(
oaNotify
.
getId
())){
oaNotify
=
oaNotifyService
.
getRecordList
(
oaNotify
);
}
model
.
addAttribute
(
"oaNotify"
,
oaNotify
);
return
"modules/oa/oaNotifyForm"
;
}
@RequiresPermissions
(
value
={
"oa:oaNotify:add"
,
"oa:oaNotify:edit"
},
logical
=
Logical
.
OR
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
OaNotify
oaNotify
,
Model
model
,
HttpServletRequest
request
,
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
oaNotify
)){
return
form
(
oaNotify
,
model
,
request
,
response
);
}
// 如果是修改,则状态为已发布,则不能再进行操作
if
(
StringUtils
.
isNotBlank
(
oaNotify
.
getId
())){
OaNotify
e
=
oaNotifyService
.
get
(
oaNotify
.
getId
());
if
(
"1"
.
equals
(
e
.
getStatus
())){
addMessage
(
redirectAttributes
,
"已发布,不能操作!"
);
return
"redirect:"
+
adminPath
+
"/oa/oaNotify/?repage"
;
}
}
oaNotifyService
.
save
(
oaNotify
);
addMessage
(
redirectAttributes
,
"保存通知'"
+
oaNotify
.
getTitle
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/oa/oaNotify/?repage"
;
}
@RequiresPermissions
(
"oa:oaNotify:del"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
OaNotify
oaNotify
,
RedirectAttributes
redirectAttributes
)
{
oaNotifyService
.
delete
(
oaNotify
);
addMessage
(
redirectAttributes
,
"删除通知成功"
);
return
"redirect:"
+
adminPath
+
"/oa/oaNotify/?repage"
;
}
@RequiresPermissions
(
"oa:oaNotify:del"
)
@RequestMapping
(
value
=
"deleteAll"
)
public
String
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
String
idArray
[]
=
ids
.
split
(
","
);
long
successCount
=
0
,
failureCount
=
0
;
String
failureMsg
=
""
;
for
(
String
id
:
idArray
){
OaNotify
oaNotify
=
oaNotifyService
.
get
(
id
);
if
(
oaNotify
==
null
){
failureCount
++;
failureMsg
+=
"id:"
+
id
+
",查询数据为空;"
;
continue
;
}
oaNotifyService
.
delete
(
oaNotifyService
.
get
(
id
));
successCount
++;
}
addMessage
(
redirectAttributes
,
"删除通知成功条数:"
+
successCount
+
",删除通知失败条数:"
+
failureCount
+
",失败信息:"
+
failureMsg
+
""
);
return
"redirect:"
+
adminPath
+
"/oa/oaNotify/?repage"
;
}
/**
* 我的通知列表
* @throws Exception
*/
@RequestMapping
(
value
=
"self"
)
public
String
selfList
(
OaNotify
oaNotify
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
throws
Exception
{
oaNotify
.
setSelf
(
true
);
Page
<
OaNotify
>
page
=
new
Page
<
OaNotify
>();
page
=
oaNotifyService
.
find
(
new
Page
<
OaNotify
>(
request
,
response
),
oaNotify
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/oa/oaNotifyList"
;
}
/**
* 我的通知列表-数据
*/
@RequiresPermissions
(
"oa:oaNotify:view"
)
@RequestMapping
(
value
=
"selfData"
)
@ResponseBody
public
Page
<
OaNotify
>
listData
(
OaNotify
oaNotify
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
oaNotify
.
setSelf
(
true
);
Page
<
OaNotify
>
page
=
oaNotifyService
.
find
(
new
Page
<
OaNotify
>(
request
,
response
),
oaNotify
);
return
page
;
}
/**
* 查看我的通知,重定向在当前页面打开
*/
@RequestMapping
(
value
=
"view"
)
public
String
view
(
OaNotify
oaNotify
,
Model
model
)
{
if
(
StringUtils
.
isNotBlank
(
oaNotify
.
getId
())){
oaNotifyService
.
updateReadFlag
(
oaNotify
);
oaNotify
=
oaNotifyService
.
getRecordList
(
oaNotify
);
model
.
addAttribute
(
"oaNotify"
,
oaNotify
);
return
"modules/oa/oaNotifyForm"
;
}
return
"redirect:"
+
adminPath
+
"/oa/oaNotify/self?repage"
;
}
/**
* 查看我的通知-数据
*/
@RequestMapping
(
value
=
"viewData"
)
@ResponseBody
public
OaNotify
viewData
(
OaNotify
oaNotify
,
Model
model
)
{
if
(
StringUtils
.
isNotBlank
(
oaNotify
.
getId
())){
oaNotifyService
.
updateReadFlag
(
oaNotify
);
return
oaNotify
;
}
return
null
;
}
/**
* 查看我的通知-发送记录
*/
@RequestMapping
(
value
=
"viewRecordData"
)
@ResponseBody
public
OaNotify
viewRecordData
(
OaNotify
oaNotify
,
Model
model
)
{
if
(
StringUtils
.
isNotBlank
(
oaNotify
.
getId
())){
oaNotify
=
oaNotifyService
.
getRecordList
(
oaNotify
);
return
oaNotify
;
}
return
null
;
}
/**
* 获取我的通知数目
*/
@RequestMapping
(
value
=
"self/count"
)
@ResponseBody
public
String
selfCount
(
OaNotify
oaNotify
,
Model
model
)
{
oaNotify
.
setSelf
(
true
);
oaNotify
.
setReadFlag
(
"0"
);
return
String
.
valueOf
(
oaNotifyService
.
findCount
(
oaNotify
));
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/oa/web/TestAuditController.java
0 → 100644
View file @
dd7c8801
/**
* Copyright © 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package
com.jeespring.modules.oa.web
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.sys.entity.User
;
import
com.jeespring.modules.sys.utils.UserUtils
;
import
com.jeespring.modules.oa.entity.TestAudit
;
import
com.jeespring.modules.oa.service.TestAuditService
;
/**
* 审批Controller
* @author thinkgem
* @version 2014-05-16
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/oa/testAudit"
)
public
class
TestAuditController
extends
AbstractBaseController
{
@Autowired
private
TestAuditService
testAuditService
;
@ModelAttribute
public
TestAudit
get
(
@RequestParam
(
required
=
false
)
String
id
){
//,
// @RequestParam(value="act.procInsId", required=false) String procInsId) {
TestAudit
testAudit
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
testAudit
=
testAuditService
.
get
(
id
);
// }else if (StringUtils.isNotBlank(procInsId)){
// testAudit = testAuditService.getByProcInsId(procInsId);
}
if
(
testAudit
==
null
){
testAudit
=
new
TestAudit
();
}
return
testAudit
;
}
@RequiresPermissions
(
"oa:testAudit:view"
)
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
TestAudit
testAudit
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
User
user
=
UserUtils
.
getUser
();
if
(!
user
.
isAdmin
()){
testAudit
.
setCreateBy
(
user
);
}
Page
<
TestAudit
>
page
=
testAuditService
.
findPage
(
new
Page
<
TestAudit
>(
request
,
response
),
testAudit
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/oa/testAuditList"
;
}
/**
* 申请单填写
* @param testAudit
* @param model
* @return
*/
@RequiresPermissions
(
"oa:testAudit:view"
)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
TestAudit
testAudit
,
Model
model
)
{
String
view
=
"testAuditForm"
;
// 查看审批申请单
if
(
StringUtils
.
isNotBlank
(
testAudit
.
getId
())){
//.getAct().getProcInsId())){
// 环节编号
String
taskDefKey
=
testAudit
.
getAct
().
getTaskDefKey
();
// 查看工单
if
(
testAudit
.
getAct
().
isFinishTask
()){
view
=
"testAuditView"
;
}
// 修改环节
else
if
(
"modify"
.
equals
(
taskDefKey
)){
view
=
"testAuditForm"
;
}
// 审核环节
else
if
(
"audit"
.
equals
(
taskDefKey
)){
view
=
"testAuditAudit"
;
// String formKey = "/oa/testAudit";
// return "redirect:" + ActUtils.getFormUrl(formKey, testAudit.getAct());
}
// 审核环节2
else
if
(
"audit2"
.
equals
(
taskDefKey
)){
view
=
"testAuditAudit"
;
}
// 审核环节3
else
if
(
"audit3"
.
equals
(
taskDefKey
)){
view
=
"testAuditAudit"
;
}
// 审核环节4
else
if
(
"audit4"
.
equals
(
taskDefKey
)){
view
=
"testAuditAudit"
;
}
// 兑现环节
else
if
(
"apply_end"
.
equals
(
taskDefKey
)){
view
=
"testAuditAudit"
;
}
}
model
.
addAttribute
(
"testAudit"
,
testAudit
);
return
"modules/oa/"
+
view
;
}
/**
* 申请单保存/修改
* @param testAudit
* @param model
* @param redirectAttributes
* @return
*/
@RequiresPermissions
(
"oa:testAudit:edit"
)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
TestAudit
testAudit
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
testAudit
)){
return
form
(
testAudit
,
model
);
}
testAuditService
.
save
(
testAudit
);
addMessage
(
redirectAttributes
,
"提交审批'"
+
testAudit
.
getUser
().
getName
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/act/task/todo/"
;
}
/**
* 工单执行(完成任务)
* @param testAudit
* @param model
* @return
*/
@RequiresPermissions
(
"oa:testAudit:edit"
)
@RequestMapping
(
value
=
"saveAudit"
)
public
String
saveAudit
(
TestAudit
testAudit
,
Model
model
)
{
if
(
StringUtils
.
isBlank
(
testAudit
.
getAct
().
getFlag
())
||
StringUtils
.
isBlank
(
testAudit
.
getAct
().
getComment
())){
addMessage
(
model
,
"请填写审核意见。"
);
return
form
(
testAudit
,
model
);
}
testAuditService
.
auditSave
(
testAudit
);
return
"redirect:"
+
adminPath
+
"/act/task/todo/"
;
}
/**
* 删除工单
* @param id
* @param redirectAttributes
* @return
*/
@RequiresPermissions
(
"oa:testAudit:edit"
)
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
TestAudit
testAudit
,
RedirectAttributes
redirectAttributes
)
{
testAuditService
.
delete
(
testAudit
);
addMessage
(
redirectAttributes
,
"删除审批成功"
);
return
"redirect:"
+
adminPath
+
"/oa/testAudit/?repage"
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/oauth/entity/TokenInfo.java
0 → 100644
View file @
dd7c8801
package
com.jeespring.modules.oauth.entity
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
java.io.Serializable
;
import
java.util.Date
;
public
class
TokenInfo
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
token
;
private
Date
tokenDate
;
private
String
oauthId
;
private
String
oauthSecret
;
private
String
ip
;
public
String
getToken
()
{
return
token
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
public
Date
getTokenDate
()
{
return
tokenDate
;
}
public
void
setTokenDate
(
Date
tokenDate
)
{
this
.
tokenDate
=
tokenDate
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getOauthId
()
{
return
oauthId
;
}
public
void
setOauthId
(
String
oauthId
)
{
this
.
oauthId
=
oauthId
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getOauthSecret
()
{
return
oauthSecret
;
}
public
void
setOauthSecret
(
String
oauthSecret
)
{
this
.
oauthSecret
=
oauthSecret
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getIp
()
{
return
ip
;
}
public
void
setIp
(
String
ip
)
{
this
.
ip
=
ip
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/oauth/rest/oauthRestController.java
0 → 100644
View file @
dd7c8801
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.oauth.rest
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.common.web.Result
;
import
com.jeespring.common.web.ResultFactory
;
import
com.jeespring.modules.oauth.service.OauthService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* 系统配置Controller
* @author 黄炳桂 516821420@qq.com
* @version 2017-11-17
*/
@RestController
@RequestMapping
(
value
=
"/rest/oauth"
)
@Api
(
value
=
"Oauth平台授权接口(分布式)"
,
description
=
"Oauth平台授权接口(分布式)"
)
public
class
oauthRestController
extends
AbstractBaseController
{
@Autowired
private
OauthService
oauthService
;
@RequestMapping
(
value
=
{
"test"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"token test平台授权测试接口(Content-Type为text/html)"
,
notes
=
"token test平台授权测试接口(Content-Type为text/html)"
)
public
Result
test
()
{
return
ResultFactory
.
getSuccessResult
(
"测试成功!"
);
}
@RequestMapping
(
value
=
{
"token"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"token平台授权接口(Content-Type为text/html)"
,
notes
=
"token平台授权接口(Content-Type为text/html)"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"oauthId"
,
value
=
"客户id"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
),
@ApiImplicitParam
(
name
=
"oauthSecret"
,
value
=
"客户密钥"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
})
public
Result
tokenRequestParam
(
@RequestParam
(
required
=
false
)
String
oauthId
,
@RequestParam
(
required
=
false
)
String
oauthSecret
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
return
oauthService
.
token
(
oauthId
,
oauthSecret
,
request
.
getRemoteAddr
());
}
@RequestMapping
(
value
=
{
"token/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"系统配置信息(Content-Type为application/json)"
,
notes
=
"系统配置信息(Content-Type为application/json)"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"oauthId"
,
value
=
"客户id"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
),
@ApiImplicitParam
(
name
=
"oauthSecret"
,
value
=
"客户密钥"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
})
public
Result
tokenJsonRequestBody
(
@RequestBody
String
oauthId
,
@RequestBody
String
oauthSecret
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
return
oauthService
.
token
(
oauthId
,
oauthSecret
,
request
.
getRemoteAddr
());
}
@RequestMapping
(
value
=
{
"checkToken"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"checkToken平台Token检查接口(Content-Type为text/html)"
,
notes
=
"checkToken平台Token检查接口(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"token"
,
value
=
"token"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
checkTokenRequestParam
(
@RequestParam
(
required
=
false
)
String
token
,
HttpServletRequest
request
,
HttpServletResponse
response
){
return
oauthService
.
checkToken
(
token
,
request
.
getRemoteAddr
());
}
@RequestMapping
(
value
=
{
"checkToken/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"checkToken平台Token检查接口(Content-Type为application/json)"
,
notes
=
"checkToken平台Token检查接口(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"token"
,
value
=
"token"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
checkTokenRequestBody
(
@RequestBody
(
required
=
false
)
String
token
,
HttpServletRequest
request
,
HttpServletResponse
response
){
return
oauthService
.
checkToken
(
token
,
request
.
getRemoteAddr
());
}
@RequestMapping
(
value
=
{
"faild"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"授权平台接口失败(Content-Type为application/html)"
,
notes
=
"授权平台接口失败(Content-Type为application/html)"
)
public
Result
faild
(
HttpServletRequest
request
,
HttpServletResponse
response
){
return
ResultFactory
.
getErrorResult
(
"oauth token授权失败!"
);
}
@RequestMapping
(
value
=
{
"apiTimeLimiFaild"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"授权平台调用次数失败(Content-Type为application/html)"
,
notes
=
"授权平台调用次数失败(Content-Type为application/html)"
)
public
Result
apiTimeLimiFaild
(
HttpServletRequest
request
,
HttpServletResponse
response
){
String
apiTimeLimi
=
request
.
getParameter
(
"apiTimeLimi"
);
if
(
apiTimeLimi
==
null
)
apiTimeLimi
=
""
;
return
ResultFactory
.
getErrorResult
(
"调用失败,接口允许最多调用"
+
apiTimeLimi
+
"次数!15分钟后解锁!"
);
}
@RequestMapping
(
value
=
{
"userOnlineAmountFaild"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"在线用户数量已满失败(Content-Type为application/html)"
,
notes
=
"在线用户数量已满失败(Content-Type为application/html)"
)
public
Result
userOnlineAmountFaild
(
HttpServletRequest
request
,
HttpServletResponse
response
){
return
oauthService
.
userOnlineAmount
();
}
@RequestMapping
(
value
=
{
"userOnlineAmount"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"在线用户数量(Content-Type为application/html)"
,
notes
=
"在线用户数量(Content-Type为application/html)"
)
public
Result
userOnlineAmount
(
HttpServletRequest
request
,
HttpServletResponse
response
){
return
oauthService
.
userOnlineAmount
();
}
@RequestMapping
(
value
=
{
"getApiTimeLimi"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"授权平台调用次数(Content-Type为application/html)"
,
notes
=
"授权平台调用次数(Content-Type为application/html)"
)
public
Result
getApiTimeLimi
(
HttpServletRequest
request
,
HttpServletResponse
response
){
return
oauthService
.
getApiTimeLimi
(
request
.
getRemoteAddr
());
}
@RequestMapping
(
value
=
{
"getApiTime"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"调用次数(Content-Type为application/html)"
,
notes
=
"调用次数(Content-Type为application/html)"
)
public
Result
getApiTime
(
HttpServletRequest
request
,
HttpServletResponse
response
){
return
oauthService
.
getApiTime
();
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/oauth/service/OauthService.java
0 → 100644
View file @
dd7c8801
package
com.jeespring.modules.oauth.service
;
import
com.jeespring.common.redis.RedisUtils
;
import
com.jeespring.common.utils.IdGen
;
import
com.jeespring.common.web.Result
;
import
com.jeespring.common.web.ResultFactory
;
import
com.jeespring.modules.sys.dao.UserDao
;
import
com.jeespring.modules.sys.entity.SysConfig
;
import
com.jeespring.modules.oauth.entity.TokenInfo
;
import
com.jeespring.modules.sys.entity.User
;
import
com.jeespring.modules.sys.service.SysConfigService
;
import
io.swagger.models.auth.In
;
import
org.apache.shiro.SecurityUtils
;
import
org.apache.shiro.session.Session
;
import
org.apache.shiro.subject.Subject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
@Service
public
class
OauthService
{
@Autowired
private
UserDao
userDao
;
@Autowired
private
SysConfigService
sysConfigService
;
@Autowired
private
RedisUtils
redisUtils
;
public
boolean
isOauthOpen
(){
SysConfig
sysConfigOauth
=
new
SysConfig
();
sysConfigOauth
.
setType
(
"oauthOpen"
);
SysConfig
sysConfigsOauth
=
sysConfigService
.
findListFirstCache
(
sysConfigOauth
);
if
(
sysConfigsOauth
.
getValue
().
equals
(
"true"
))
return
true
;
return
false
;
}
public
Result
token
(
String
oauthId
,
String
oauthSecret
,
String
ip
){
if
(
oauthId
==
null
||
oauthSecret
==
null
)
{
return
ResultFactory
.
getErrorResult
(
"授权ID和授权密钥不能为空!"
);
}
String
tokenTime
=
"360000"
;
String
tokenRedis
=
String
.
valueOf
(
redisUtils
.
get
(
oauthId
));
if
(
tokenRedis
!=
null
){
TokenInfo
tokenInfoRedis
=(
TokenInfo
)
redisUtils
.
get
(
tokenRedis
);
redisUtils
.
remove
(
oauthId
);
redisUtils
.
remove
(
tokenInfoRedis
.
getToken
());
redisUtils
.
remove
(
ip
);
redisUtils
.
set
(
tokenInfoRedis
.
getToken
(),
tokenInfoRedis
,
Long
.
valueOf
(
tokenTime
));
redisUtils
.
set
(
oauthId
,
tokenInfoRedis
.
getToken
(),
Long
.
valueOf
(
tokenTime
));
redisUtils
.
set
(
ip
,
tokenInfoRedis
.
getToken
(),
Long
.
valueOf
(
tokenTime
));
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
tokenInfoRedis
);
return
result
;
}
SysConfig
sysConfigTokenTime
=
new
SysConfig
();
sysConfigTokenTime
.
setType
(
"tokenTime"
);
List
<
SysConfig
>
sysConfigsTokenTimes
=
sysConfigService
.
findList
(
sysConfigTokenTime
);
if
(
sysConfigsTokenTimes
.
size
()>
0
){
tokenTime
=
sysConfigsTokenTimes
.
get
(
0
).
getValue
();
}
User
user
=
new
User
();
user
.
setOauthId
(
oauthId
);
user
.
setOauthSecret
(
oauthSecret
);
List
<
User
>
users
=
userDao
.
findList
(
user
);
SysConfig
sysConfigOauthId
=
new
SysConfig
();
sysConfigOauthId
.
setType
(
"oauthId"
);
List
<
SysConfig
>
sysConfigsOauthId
=
sysConfigService
.
findList
(
sysConfigOauthId
);
SysConfig
sysConfigOauthSecret
=
new
SysConfig
();
sysConfigOauthSecret
.
setType
(
"oauthSecret"
);
List
<
SysConfig
>
sysConfigsOauthSecret
=
sysConfigService
.
findList
(
sysConfigOauthSecret
);
if
(
sysConfigsOauthId
.
size
()>
0
&&
sysConfigsOauthSecret
.
size
()>
0
&&
(!
sysConfigsOauthId
.
get
(
0
).
getValue
().
equals
(
oauthId
)
||
!
sysConfigsOauthSecret
.
get
(
0
).
getValue
().
equals
(
oauthSecret
))){
return
ResultFactory
.
getErrorResult
(
"授权ID和授权密钥不正确!"
);
}
if
(
sysConfigsOauthId
.
size
()==
0
&&
sysConfigsOauthSecret
.
size
()==
0
&&
users
.
size
()!=
1
){
return
ResultFactory
.
getErrorResult
(
"授权ID和授权密钥不正确!"
);
}
Result
result
=
ResultFactory
.
getSuccessResult
();
TokenInfo
tokenInfo
=
new
TokenInfo
();
tokenInfo
.
setToken
(
IdGen
.
uuid
());
tokenInfo
.
setTokenDate
(
new
Date
());
tokenInfo
.
setOauthId
(
oauthId
);
tokenInfo
.
setOauthSecret
(
oauthSecret
);
tokenInfo
.
setIp
(
ip
);
result
.
setResultObject
(
tokenInfo
);
redisUtils
.
set
(
tokenInfo
.
getToken
(),
tokenInfo
,
Long
.
valueOf
(
tokenTime
));
redisUtils
.
set
(
oauthId
,
tokenInfo
.
getToken
(),
Long
.
valueOf
(
tokenTime
));
redisUtils
.
set
(
ip
,
tokenInfo
.
getToken
(),
Long
.
valueOf
(
tokenTime
));
return
result
;
}
public
Result
checkToken
(
String
token
,
String
ip
){
String
tokenRedis
=
String
.
valueOf
(
redisUtils
.
get
(
ip
));
if
(
token
==
null
&&
tokenRedis
==
null
){
return
ResultFactory
.
getErrorResult
(
"token不能为空!"
);
}
if
(
token
==
null
&&
tokenRedis
!=
null
){
TokenInfo
tokenInfoRedis
=(
TokenInfo
)
redisUtils
.
get
(
tokenRedis
);
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
tokenInfoRedis
);
return
result
;
}
SysConfig
sysConfigOauth
=
new
SysConfig
();
sysConfigOauth
.
setType
(
"oauthOpen"
);
List
<
SysConfig
>
sysConfigsOauth
=
sysConfigService
.
findList
(
sysConfigOauth
);
if
(
sysConfigsOauth
.
size
()<=
0
){
Result
result
=
ResultFactory
.
getErrorResult
(
"oauth权限服务未开启!"
);
result
.
setResultCode
(
100
);
return
result
;
}
if
(
sysConfigsOauth
.
get
(
0
).
getValue
()==
"false"
){
Result
result
=
ResultFactory
.
getErrorResult
(
"oauth权限服务未开启!"
);
result
.
setResultCode
(
100
);
return
result
;
}
TokenInfo
tokenInfo
=(
TokenInfo
)
redisUtils
.
get
(
token
);
if
(
tokenInfo
==
null
){
return
ResultFactory
.
getErrorResult
(
"Token不正确!"
);
}
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
tokenInfo
);
return
result
;
}
public
Result
userOnlineAmount
(){
SysConfig
userOnlineAmount
=
new
SysConfig
();
userOnlineAmount
.
setType
(
"userOnlineAmount"
);
userOnlineAmount
=
sysConfigService
.
findListFirstCache
(
userOnlineAmount
);
int
countShiro
=
redisUtils
.
getCountShiro
();
Subject
subject
=
SecurityUtils
.
getSubject
();
String
key
=
null
;
if
(
subject
!=
null
&&
subject
.
getSession
()
!=
null
)
key
=
redisUtils
.
SHIRO_REDIS
+
":"
+
subject
.
getSession
().
getId
().
toString
();
if
(
Integer
.
valueOf
(
userOnlineAmount
.
getValue
())<
countShiro
&&
key
!=
null
){
redisUtils
.
remove
(
key
);
return
ResultFactory
.
getErrorResult
(
"在线控制:在线"
+
countShiro
+
"人/总控制"
+
userOnlineAmount
.
getValue
()+
"人"
);
}
if
(!
redisUtils
.
exists
(
key
)){
return
ResultFactory
.
getErrorResult
(
"在线控制:在线"
+
countShiro
+
"人/总控制"
+
userOnlineAmount
.
getValue
()+
"人"
);
}
return
ResultFactory
.
getSuccessResult
(
"在线控制:在线"
+
countShiro
+
"人/总控制"
+
userOnlineAmount
.
getValue
()+
"人"
);
}
public
Result
getApiTimeLimi
(
String
ip
){
String
redisKey
=
"ApiTimeLimi_"
+
ip
;
SysConfig
apiTimeLimi
=
new
SysConfig
();
apiTimeLimi
.
setType
(
"apiTimeLimi"
);
apiTimeLimi
=
sysConfigService
.
findListFirstCache
(
apiTimeLimi
);
Object
result
=
redisUtils
.
get
(
redisKey
);
if
(
result
==
null
){
return
ResultFactory
.
getSuccessResult
(
"/"
+
apiTimeLimi
.
getValue
());
}
return
ResultFactory
.
getSuccessResult
(
result
+
"/"
+
apiTimeLimi
.
getValue
());
}
public
Result
getApiTime
(){
String
redisKeyDay
=
"ApiTimeDate"
;
String
redisKeyMonth
=
"ApiTimeMonth"
;
Object
apiTimeDay
=
redisUtils
.
get
(
redisKeyDay
);
Object
apiTimeMonth
=
redisUtils
.
get
(
redisKeyMonth
);
if
(
apiTimeDay
==
null
)
apiTimeDay
=
"0"
;
if
(
apiTimeMonth
==
null
)
apiTimeMonth
=
"0"
;
return
ResultFactory
.
getSuccessResult
(
"Day:"
+
apiTimeDay
+
" Time;Month:"
+
apiTimeMonth
+
" Time"
);
}
public
Result
setApiTime
(){
String
redisKeyDay
=
"ApiTimeDate"
;
String
redisKeyMonth
=
"ApiTimeMonth"
;
Object
apiTimeDay
=
redisUtils
.
get
(
redisKeyDay
);
Object
apiTimeMonth
=
redisUtils
.
get
(
redisKeyMonth
);
Long
apiTimeDayLong
=
0L
;
Long
apiTimeMonthLong
=
0L
;
if
(
apiTimeDay
==
null
)
apiTimeDay
=
0
;
if
(
apiTimeMonth
==
null
)
apiTimeMonth
=
0
;
if
(
apiTimeDay
!=
null
){
apiTimeDayLong
=
Long
.
valueOf
(
apiTimeDay
.
toString
());
apiTimeDayLong
=
apiTimeDayLong
+
1
;
}
if
(
apiTimeMonth
!=
null
){
apiTimeMonthLong
=
Long
.
valueOf
(
apiTimeMonth
.
toString
());
apiTimeMonthLong
=
apiTimeMonthLong
+
1
;
}
redisUtils
.
set
(
redisKeyDay
,
apiTimeDayLong
,
1L
,
TimeUnit
.
DAYS
);
redisUtils
.
set
(
redisKeyMonth
,
apiTimeMonthLong
,
30L
,
TimeUnit
.
DAYS
);
return
ResultFactory
.
getSuccessResult
(
"Day:"
+
apiTimeDayLong
+
" Time;Month:"
+
apiTimeMonthLong
+
" Time"
);
}
public
Result
ApiTimeLimi
(
String
ip
){
String
redisKey
=
"ApiTimeLimi_"
+
ip
;
Object
apiTime
=
redisUtils
.
get
(
redisKey
);
if
(
apiTime
==
null
){
apiTime
=
0
;
}
Object
apiTimeLongRedis
=
redisUtils
.
get
(
redisKey
);
Long
apiTimeLong
=
0L
;
if
(
apiTimeLongRedis
!=
null
){
apiTimeLong
=
Long
.
valueOf
(
apiTimeLongRedis
.
toString
());
}
Long
apiTimeLongSysConfig
=
0L
;
apiTimeLong
+=
1
;
SysConfig
apiTimeLimi
=
new
SysConfig
();
apiTimeLimi
.
setType
(
"apiTimeLimi"
);
List
<
SysConfig
>
apiTimeLimis
=
sysConfigService
.
findList
(
apiTimeLimi
);
if
(
apiTimeLimis
.
size
()>
0
){
apiTimeLongSysConfig
=
Long
.
valueOf
(
apiTimeLimis
.
get
(
0
).
getValue
());
}
if
(
apiTimeLongSysConfig
.
equals
(
"-1"
)){
apiTimeLongSysConfig
=
100000000L
;
}
if
(
apiTimeLimis
.
size
()==
0
){
apiTimeLongSysConfig
=
10000L
;
}
if
(
apiTime
!=
null
&&
apiTimeLongSysConfig
>
apiTimeLong
){
redisUtils
.
remove
(
redisKey
);
}
if
(
apiTimeLongSysConfig
<=
apiTimeLong
){
Result
result
=
ResultFactory
.
getErrorResult
(
"调用失败,接口允许最多调用"
+
apiTimeLongSysConfig
+
"次!"
);
result
.
setResultObject
(
apiTimeLongSysConfig
);
return
result
;
}
redisUtils
.
set
(
redisKey
,
apiTimeLong
);
return
ResultFactory
.
getSuccessResult
();
}
}
Prev
1
…
13
14
15
16
17
18
19
20
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment