Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
roncoo
roncoo-education
提交
c39e6792
R
roncoo-education
项目概览
roncoo
/
roncoo-education
大约 1 年 前同步成功
通知
146
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roncoo-education
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c39e6792
编写于
12月 16, 2020
作者:
夏天飘过的风
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改配置文件
上级
ddbc3b1d
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
359 addition
and
198 deletion
+359
-198
nacos_config.zip
nacos_config.zip
+0
-0
roncoo-education-app-gateway/src/main/java/com/roncoo/education/ServerGatewayApplication.java
...n/java/com/roncoo/education/ServerGatewayApplication.java
+20
-21
roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/common/FilterPre.java
...va/com/roncoo/education/app/gateway/common/FilterPre.java
+75
-73
roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/controller/HandlerController.java
...o/education/app/gateway/controller/HandlerController.java
+39
-0
roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/controller/IndexController.java
...coo/education/app/gateway/controller/IndexController.java
+5
-5
roncoo-education-app-gateway/src/main/resources/bootstrap.properties
...ation-app-gateway/src/main/resources/bootstrap.properties
+3
-3
roncoo-education-app-gateway/src/main/resources/templates/index.ftl
...cation-app-gateway/src/main/resources/templates/index.ftl
+7
-7
roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/MsgSendCrontab.java
...ain/java/com/roncoo/education/app/job/MsgSendCrontab.java
+48
-0
roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/OrderCrontab.java
.../main/java/com/roncoo/education/app/job/OrderCrontab.java
+46
-0
roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/VideoCrontab.java
.../main/java/com/roncoo/education/app/job/VideoCrontab.java
+68
-0
roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/VideoCrontab.java
...in/java/com/roncoo/education/server/job/VideoCrontab.java
+0
-69
roncoo-education-app-sba/src/main/java/com/roncoo/education/app/sba/ServerSbaApplication.java
...va/com/roncoo/education/app/sba/ServerSbaApplication.java
+5
-6
roncoo-education-app-sba/src/main/java/com/roncoo/education/app/sba/config/SecuritySecureConfig.java
...roncoo/education/app/sba/config/SecuritySecureConfig.java
+28
-0
roncoo-education-util/src/main/resources/logback-roncoo.xml
roncoo-education-util/src/main/resources/logback-roncoo.xml
+15
-14
未找到文件。
nacos_config.zip
浏览文件 @
c39e6792
无法预览此类型文件
roncoo-education-app-gateway/src/main/java/com/roncoo/education/ServerGatewayApplication.java
浏览文件 @
c39e6792
...
...
@@ -3,6 +3,7 @@
*/
package
com.roncoo.education
;
import
com.roncoo.education.app.gateway.common.FilterPre
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.cloud.client.SpringCloudApplication
;
import
org.springframework.cloud.netflix.zuul.EnableZuulProxy
;
...
...
@@ -11,8 +12,6 @@ import org.springframework.web.cors.CorsConfiguration;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
com.roncoo.education.server.gateway.common.FilterPre
;
/**
* 服务网关
*
...
...
@@ -22,26 +21,26 @@ import com.roncoo.education.server.gateway.common.FilterPre;
@SpringCloudApplication
public
class
ServerGatewayApplication
{
@Bean
public
CorsFilter
corsFilter
()
{
final
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
final
CorsConfiguration
config
=
new
CorsConfiguration
();
config
.
setAllowCredentials
(
true
);
config
.
addAllowedOrigin
(
"*"
);
config
.
addAllowedHeader
(
"*"
);
config
.
addAllowedMethod
(
"*"
);
config
.
setMaxAge
(
18000L
);
source
.
registerCorsConfiguration
(
"/**"
,
config
);
return
new
CorsFilter
(
source
);
}
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ServerGatewayApplication
.
class
,
args
);
}
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ServerGatewayApplication
.
class
,
args
);
}
@Bean
public
FilterPre
filterPre
()
{
return
new
FilterPre
();
}
@Bean
public
FilterPre
filterPre
()
{
return
new
FilterPre
();
}
@Bean
public
CorsFilter
corsFilter
()
{
final
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
final
CorsConfiguration
config
=
new
CorsConfiguration
();
config
.
setAllowCredentials
(
true
);
config
.
addAllowedOrigin
(
"*"
);
config
.
addAllowedHeader
(
"*"
);
config
.
addAllowedMethod
(
"*"
);
config
.
setMaxAge
(
18000L
);
source
.
registerCorsConfiguration
(
"/**"
,
config
);
return
new
CorsFilter
(
source
);
}
}
roncoo-education-app-gateway/src/main/java/com/roncoo/education/
server
/gateway/common/FilterPre.java
→
roncoo-education-app-gateway/src/main/java/com/roncoo/education/
app
/gateway/common/FilterPre.java
浏览文件 @
c39e6792
/**
* Copyright 2015-现在 广州市领课网络科技有限公司
*/
package
com.roncoo.education.server.gateway.common
;
import
java.io.BufferedReader
;
import
java.io.DataInputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.concurrent.TimeUnit
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
com.netflix.zuul.exception.ZuulException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.netflix.zuul.filters.support.FilterConstants
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.util.StringUtils
;
package
com.roncoo.education.app.gateway.common
;
import
com.auth0.jwt.interfaces.DecodedJWT
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.exception.ZuulException
;
import
com.netflix.zuul.http.ServletInputStreamWrapper
;
import
com.roncoo.education.util.base.BaseException
;
import
com.roncoo.education.util.base.Result
;
import
com.roncoo.education.util.enums.RedisPreEnum
;
import
com.roncoo.education.util.enums.ResultEnum
;
import
com.roncoo.education.util.tools.JSONUtil
;
import
com.roncoo.education.util.tools.JWTUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.netflix.zuul.filters.support.FilterConstants
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.util.StringUtils
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
java.io.BufferedReader
;
import
java.io.DataInputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.concurrent.TimeUnit
;
/**
* 请求开始前执行
...
...
@@ -47,6 +44,51 @@ public class FilterPre extends ZuulFilter {
@Autowired
private
StringRedisTemplate
stringRedisTemplate
;
@SuppressWarnings
(
"unchecked"
)
private
static
TreeMap
<
String
,
Object
>
getParamMap
(
HttpServletRequest
request
)
{
TreeMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
Map
<
String
,
String
[]>
map
=
request
.
getParameterMap
();
for
(
String
key
:
map
.
keySet
())
{
paramMap
.
put
(
key
,
map
.
get
(
key
)[
0
]);
}
if
(
paramMap
.
isEmpty
())
{
DataInputStream
in
=
null
;
try
{
in
=
new
DataInputStream
(
request
.
getInputStream
());
byte
[]
buf
=
new
byte
[
request
.
getContentLength
()];
in
.
readFully
(
buf
);
String
t
=
new
String
(
buf
,
"UTF-8"
);
if
(
StringUtils
.
hasText
(
t
))
{
return
new
TreeMap
<>(
JSONUtil
.
parseObject
(
t
,
TreeMap
.
class
));
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取不到任何参数"
);
}
finally
{
if
(
null
!=
in
)
try
{
in
.
close
();
// 关闭数据流
}
catch
(
IOException
e
)
{
logger
.
error
(
"关闭数据流异常"
);
}
}
}
return
paramMap
;
}
// 校验用户是否有权限
private
static
Boolean
checkUri
(
String
uri
,
String
tk
)
{
List
<
String
>
menuVOList1
=
JSONUtil
.
parseArray
(
tk
,
String
.
class
);
if
(
StringUtils
.
hasText
(
uri
)
&&
uri
.
endsWith
(
"/"
))
{
uri
=
uri
.
substring
(
0
,
uri
.
length
()
-
1
);
}
for
(
String
s
:
menuVOList1
)
{
if
(
s
.
contains
(
uri
))
{
return
true
;
}
}
return
false
;
}
@Override
public
String
filterType
()
{
return
FilterConstants
.
PRE_TYPE
;
...
...
@@ -138,11 +180,16 @@ public class FilterPre extends ZuulFilter {
}
// 单点登录处理,注意,登录的时候必须要放入缓存
/*
* if (!stringRedisTemplate.hasKey(userNo.toString())) { // 不存在,则登录异常,有效期为1小时 throw new BaseException(ResultEnum.TOKEN_PAST); }
*
* // 存在,判断是否token相同 String tk = stringRedisTemplate.opsForValue().get(userNo.toString()); if (!token.equals(tk)) { // 不同则为不同的用户登录,这时候提示异地登录 throw new BaseException(ResultEnum.REMOTE_ERROR); }
*/
// if (!stringRedisTemplate.hasKey(userNo.toString())) {
// // 不存在,则登录异常,有效期为1小时
// throw new BaseException(ResultEnum.TOKEN_PAST);
// }
// // 存在,判断是否token相同
// String tk = stringRedisTemplate.opsForValue().get(userNo.toString());
// if (!token.equals(tk)) {
// // 不同则为不同的用户登录,这时候提示异地登录
// throw new BaseException(ResultEnum.REMOTE_ERROR);
// }
// 更新时间,使token不过期
stringRedisTemplate
.
opsForValue
().
set
(
userNo
.
toString
(),
token
,
1
,
TimeUnit
.
HOURS
);
...
...
@@ -178,49 +225,4 @@ public class FilterPre extends ZuulFilter {
}
};
}
@SuppressWarnings
(
"unchecked"
)
private
static
TreeMap
<
String
,
Object
>
getParamMap
(
HttpServletRequest
request
)
{
TreeMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
Map
<
String
,
String
[]>
map
=
request
.
getParameterMap
();
for
(
String
key
:
map
.
keySet
())
{
paramMap
.
put
(
key
,
map
.
get
(
key
)[
0
]);
}
if
(
paramMap
.
isEmpty
())
{
DataInputStream
in
=
null
;
try
{
in
=
new
DataInputStream
(
request
.
getInputStream
());
byte
[]
buf
=
new
byte
[
request
.
getContentLength
()];
in
.
readFully
(
buf
);
String
t
=
new
String
(
buf
,
"UTF-8"
);
if
(
StringUtils
.
hasText
(
t
))
{
return
new
TreeMap
<>(
JSONUtil
.
parseObject
(
t
,
TreeMap
.
class
));
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取不到任何参数"
);
}
finally
{
if
(
null
!=
in
)
try
{
in
.
close
();
// 关闭数据流
}
catch
(
IOException
e
)
{
logger
.
error
(
"关闭数据流异常"
);
}
}
}
return
paramMap
;
}
// 校验用户是否有权限
private
static
Boolean
checkUri
(
String
uri
,
String
tk
)
{
List
<
String
>
menuVOList1
=
JSONUtil
.
parseArray
(
tk
,
String
.
class
);
if
(
StringUtils
.
hasText
(
uri
)
&&
uri
.
endsWith
(
"/"
))
{
uri
=
uri
.
substring
(
0
,
uri
.
length
()
-
1
);
}
for
(
String
s
:
menuVOList1
)
{
if
(
s
.
contains
(
uri
))
{
return
true
;
}
}
return
false
;
}
}
roncoo-education-app-gateway/src/main/java/com/roncoo/education/
server
/gateway/controller/HandlerController.java
→
roncoo-education-app-gateway/src/main/java/com/roncoo/education/
app
/gateway/controller/HandlerController.java
浏览文件 @
c39e6792
package
com.roncoo.education.
server
.gateway.controller
;
package
com.roncoo.education.
app
.gateway.controller
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.exception.ZuulException
;
import
com.roncoo.education.util.base.Result
;
import
com.roncoo.education.util.enums.ResultEnum
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.web.servlet.error.ErrorController
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.exception.ZuulException
;
@Slf4j
@RestController
public
class
HandlerController
implements
ErrorController
{
/**
* 出异常后进入该方法,交由下面的方法处理
*/
@Override
public
String
getErrorPath
()
{
return
"/error"
;
}
/**
* 出异常后进入该方法,交由下面的方法处理
*/
@Override
public
String
getErrorPath
()
{
return
"/error"
;
}
@RequestMapping
(
"/error"
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
Result
<
String
>
error
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
Throwable
throwable
=
ctx
.
getThrowable
();
if
(
null
!=
throwable
&&
throwable
instanceof
ZuulException
){
ZuulException
e
=
(
ZuulException
)
ctx
.
getThrowable
();
return
Result
.
error
(
e
.
nStatusCode
,
e
.
errorCause
);
}
return
Result
.
error
(
ResultEnum
.
ERROR
);
}
@RequestMapping
(
"/error"
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
Result
<
String
>
error
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
Throwable
throwable
=
ctx
.
getThrowable
();
log
.
error
(
"系统异常"
,
throwable
);
if
(
null
!=
throwable
&&
throwable
instanceof
ZuulException
)
{
ZuulException
e
=
(
ZuulException
)
ctx
.
getThrowable
();
return
Result
.
error
(
e
.
nStatusCode
,
e
.
errorCause
);
}
return
Result
.
error
(
ResultEnum
.
ERROR
);
}
}
roncoo-education-app-gateway/src/main/java/com/roncoo/education/
server
/gateway/controller/IndexController.java
→
roncoo-education-app-gateway/src/main/java/com/roncoo/education/
app
/gateway/controller/IndexController.java
浏览文件 @
c39e6792
/**
* Copyright 2015-现在 广州市领课网络科技有限公司
*/
package
com.roncoo.education.
server
.gateway.controller
;
package
com.roncoo.education.
app
.gateway.controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -10,9 +10,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public
class
IndexController
{
@RequestMapping
(
value
=
"/"
,
method
=
RequestMethod
.
GET
)
public
String
index
()
{
return
"index"
;
}
@RequestMapping
(
value
=
"/"
,
method
=
RequestMethod
.
GET
)
public
String
index
()
{
return
"index"
;
}
}
roncoo-education-app-gateway/src/main/resources/bootstrap.properties
浏览文件 @
c39e6792
# application
spring.application.name
=
roncoo-education-app-gateway
# profile
spring.profiles.active
=
de
v
spring.profiles.active
=
de
mo
# server
server.port
=
5840
# nacos
spring.cloud.nacos.username
=
nacos
spring.cloud.nacos.password
=
nacos
spring.cloud.nacos.server-addr
=
localhost
:8848
spring.cloud.nacos.password
=
RonCoo.123
spring.cloud.nacos.server-addr
=
10.65.3.98
:8848
spring.cloud.nacos.namespace
=
${spring.profiles.active}
spring.cloud.nacos.discovery.namespace
=
${spring.cloud.nacos.namespace}
spring.cloud.nacos.config.namespace
=
${spring.cloud.nacos.namespace}
...
...
roncoo-education-app-gateway/src/main/resources/templates/index.ftl
浏览文件 @
c39e6792
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
接口文档
</title>
<meta
charset=
"UTF-8"
>
<title>
接口文档
</title>
</head>
<body>
<div
style=
"margin:0 auto;text-align:center;"
>
<div
style=
"margin:0 auto;text-align:center;"
>
<br/>
<a
href=
"http://
192.168.1.75
:5710/doc.html"
target=
"_blanck"
>
课程API
</a>
<a
href=
"http://
localhost
:5710/doc.html"
target=
"_blanck"
>
课程API
</a>
<br/>
<br/>
<a
href=
"http://
192.168.1.75
:5720/doc.html"
target=
"_blanck"
>
用户API
</a>
<a
href=
"http://
localhost
:5720/doc.html"
target=
"_blanck"
>
用户API
</a>
<br/>
<br/>
<a
href=
"http://
192.168.1.75
:5730/doc.html"
target=
"_blanck"
>
系统API
</a>
</div>
<a
href=
"http://
localhost
:5730/doc.html"
target=
"_blanck"
>
系统API
</a>
</div>
</body>
</html>
roncoo-education-app-job/src/main/java/com/roncoo/education/
server
/job/MsgSendCrontab.java
→
roncoo-education-app-job/src/main/java/com/roncoo/education/
app
/job/MsgSendCrontab.java
浏览文件 @
c39e6792
package
com.roncoo.education.
server
.job
;
package
com.roncoo.education.
app
.job
;
import
com.roncoo.education.system.feign.interfaces.IFeignMsg
;
import
com.roncoo.education.util.base.BaseController
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
com.roncoo.education.util.base.BaseController
;
/**
* 站内信-定时发送
*
* @author wuyun
*
*/
@Component
public
class
MsgSendCrontab
extends
BaseController
{
private
static
final
Object
KEY
=
new
Object
();
private
static
boolean
taskFlag
=
false
;
@Autowired
private
IFeignMsg
bossMsg
;
/**
* 定时任务,一小时启动一次
*
* @author wuyun
*/
@Scheduled
(
fixedRate
=
60000
)
public
void
pushCancel
()
{
synchronized
(
KEY
)
{
if
(
MsgSendCrontab
.
taskFlag
)
{
logger
.
warn
(
"站内信-定时发送已经启动"
);
return
;
}
MsgSendCrontab
.
taskFlag
=
true
;
}
try
{
bossMsg
.
push
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"站内信-定时发送-执行出错"
,
e
);
}
MsgSendCrontab
.
taskFlag
=
false
;
logger
.
warn
(
"站内信-定时发送-任务完成"
);
}
private
static
final
Object
KEY
=
new
Object
();
private
static
boolean
taskFlag
=
false
;
@Autowired
private
IFeignMsg
bossMsg
;
/**
* 定时任务,一小时启动一次
*
* @author wuyun
*/
@Scheduled
(
fixedRate
=
60000
)
public
void
pushCancel
()
{
synchronized
(
KEY
)
{
if
(
MsgSendCrontab
.
taskFlag
)
{
logger
.
warn
(
"站内信-定时发送已经启动"
);
return
;
}
MsgSendCrontab
.
taskFlag
=
true
;
}
try
{
bossMsg
.
push
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"站内信-定时发送-执行出错"
,
e
);
}
MsgSendCrontab
.
taskFlag
=
false
;
logger
.
warn
(
"站内信-定时发送-任务完成"
);
}
}
roncoo-education-app-job/src/main/java/com/roncoo/education/
server
/job/OrderCrontab.java
→
roncoo-education-app-job/src/main/java/com/roncoo/education/
app
/job/OrderCrontab.java
浏览文件 @
c39e6792
package
com.roncoo.education.
server
.job
;
package
com.roncoo.education.
app
.job
;
import
com.roncoo.education.course.feign.interfaces.IFeignOrderInfo
;
import
com.roncoo.education.util.base.BaseController
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
com.roncoo.education.util.base.BaseController
;
/**
* 定时任务-订单处理
*
...
...
@@ -15,33 +14,33 @@ import com.roncoo.education.util.base.BaseController;
@Component
public
class
OrderCrontab
extends
BaseController
{
private
static
final
Object
KEY
=
new
Object
();
private
static
boolean
taskFlag
=
false
;
@Autowired
private
IFeignOrderInfo
feignOrderInfo
;
/**
* 定时任务每分钟执行一次
*/
@Scheduled
(
fixedRate
=
60000
)
public
void
orderCancel
()
{
synchronized
(
KEY
)
{
if
(
OrderCrontab
.
taskFlag
)
{
logger
.
warn
(
"订单处理-任务已经启动"
);
return
;
}
OrderCrontab
.
taskFlag
=
true
;
}
logger
.
warn
(
"订单处理-定时任务开始"
);
try
{
feignOrderInfo
.
handleScheduledTasks
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"定时任务-订单处理-执行出错"
,
e
);
}
OrderCrontab
.
taskFlag
=
false
;
}
private
static
final
Object
KEY
=
new
Object
();
private
static
boolean
taskFlag
=
false
;
@Autowired
private
IFeignOrderInfo
feignOrderInfo
;
/**
* 定时任务每分钟执行一次
*/
@Scheduled
(
fixedRate
=
60000
)
public
void
orderCancel
()
{
synchronized
(
KEY
)
{
if
(
OrderCrontab
.
taskFlag
)
{
logger
.
warn
(
"订单处理-任务已经启动"
);
return
;
}
OrderCrontab
.
taskFlag
=
true
;
}
logger
.
warn
(
"订单处理-定时任务开始"
);
try
{
feignOrderInfo
.
handleScheduledTasks
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"定时任务-订单处理-执行出错"
,
e
);
}
OrderCrontab
.
taskFlag
=
false
;
}
}
roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/VideoCrontab.java
0 → 100644
浏览文件 @
c39e6792
package
com.roncoo.education.app.job
;
import
com.roncoo.education.course.feign.interfaces.IFeignCourseVideo
;
import
com.roncoo.education.util.base.BaseController
;
import
com.roncoo.education.util.config.SystemUtil
;
import
com.xiaoleilu.hutool.io.FileUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
/**
* 定时任务-视频处理
*
* @author wuyun
*/
@Component
public
class
VideoCrontab
extends
BaseController
{
private
static
final
Object
KEY
=
new
Object
();
private
static
boolean
taskFlag
=
false
;
@Autowired
private
IFeignCourseVideo
feignCourseVideo
;
/**
* 定时任务每分钟执行一次 <br/>
* 注意:每个course服务都必须要对应有一个定时任务,针对服务器
*/
@Scheduled
(
fixedRate
=
60000
)
public
void
orderCancel
()
{
synchronized
(
KEY
)
{
if
(
VideoCrontab
.
taskFlag
)
{
logger
.
warn
(
"视频处理-任务已经启动"
);
return
;
}
VideoCrontab
.
taskFlag
=
true
;
}
int
videoSum
=
0
;
File
file
=
new
File
(
SystemUtil
.
PERIOD_VIDEO_PATH
);
if
(
file
.
isDirectory
())
{
// isDirectory是否文件夹
File
[]
files
=
file
.
listFiles
();
// listFiles是获取该目录下所有文件和目录的绝对路径
for
(
File
targetFile
:
files
)
{
if
(
targetFile
.
isFile
()
&&
targetFile
.
exists
())
{
if
(
FileUtil
.
newerThan
(
targetFile
,
(
System
.
currentTimeMillis
()
-
7200000
)))
{
// 上传两个小时内
try
{
feignCourseVideo
.
handleScheduledTasks
(
targetFile
);
videoSum
=
videoSum
+
1
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"视频定时任务处理失败"
,
e
);
}
}
}
}
}
VideoCrontab
.
taskFlag
=
false
;
logger
.
warn
(
"视频处理-定时任务完成,处理视频数={}"
,
videoSum
);
}
}
roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/VideoCrontab.java
已删除
100644 → 0
浏览文件 @
ddbc3b1d
package
com.roncoo.education.server.job
;
import
java.io.File
;
import
com.roncoo.education.course.feign.interfaces.IFeignCourseVideo
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
com.roncoo.education.util.base.BaseController
;
import
com.roncoo.education.util.config.SystemUtil
;
import
com.xiaoleilu.hutool.io.FileUtil
;
/**
* 定时任务-视频处理
*
* @author wuyun
*/
@Component
public
class
VideoCrontab
extends
BaseController
{
private
static
final
Object
KEY
=
new
Object
();
private
static
boolean
taskFlag
=
false
;
@Autowired
private
IFeignCourseVideo
feignCourseVideo
;
/**
* 定时任务每分钟执行一次 <br/>
* 注意:每个course服务都必须要对应有一个定时任务,针对服务器
*/
@Scheduled
(
fixedRate
=
60000
)
public
void
orderCancel
()
{
synchronized
(
KEY
)
{
if
(
VideoCrontab
.
taskFlag
)
{
logger
.
warn
(
"视频处理-任务已经启动"
);
return
;
}
VideoCrontab
.
taskFlag
=
true
;
}
int
videoSum
=
0
;
File
file
=
new
File
(
SystemUtil
.
PERIOD_VIDEO_PATH
);
if
(
file
.
isDirectory
())
{
// isDirectory是否文件夹
File
[]
files
=
file
.
listFiles
();
// listFiles是获取该目录下所有文件和目录的绝对路径
for
(
File
targetFile
:
files
)
{
if
(
targetFile
.
isFile
()
&&
targetFile
.
exists
())
{
if
(
FileUtil
.
newerThan
(
targetFile
,
(
System
.
currentTimeMillis
()
-
7200000
)))
{
// 上传两个小时内
try
{
feignCourseVideo
.
handleScheduledTasks
(
targetFile
);
videoSum
=
videoSum
+
1
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"视频定时任务处理失败"
,
e
);
}
}
}
}
}
VideoCrontab
.
taskFlag
=
false
;
logger
.
warn
(
"视频处理-定时任务完成,处理视频数={}"
,
videoSum
);
}
}
roncoo-education-app-sba/src/main/java/com/roncoo/education/
server
/sba/ServerSbaApplication.java
→
roncoo-education-app-sba/src/main/java/com/roncoo/education/
app
/sba/ServerSbaApplication.java
浏览文件 @
c39e6792
/**
* Copyright 2015-现在 广州市领课网络科技有限公司
*/
package
com.roncoo.education.
server
.sba
;
package
com.roncoo.education.
app
.sba
;
import
de.codecentric.boot.admin.server.config.EnableAdminServer
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
de.codecentric.boot.admin.server.config.EnableAdminServer
;
@EnableAdminServer
@EnableDiscoveryClient
@SpringBootApplication
public
class
ServerSbaApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ServerSbaApplication
.
class
,
args
);
}
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ServerSbaApplication
.
class
,
args
);
}
}
roncoo-education-app-sba/src/main/java/com/roncoo/education/
server
/sba/config/SecuritySecureConfig.java
→
roncoo-education-app-sba/src/main/java/com/roncoo/education/
app
/sba/config/SecuritySecureConfig.java
浏览文件 @
c39e6792
package
com.roncoo.education.
server
.sba.config
;
package
com.roncoo.education.
app
.sba.config
;
import
de.codecentric.boot.admin.server.config.AdminServerProperties
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler
;
import
org.springframework.security.web.csrf.CookieCsrfTokenRepository
;
import
de.codecentric.boot.admin.server.config.AdminServerProperties
;
@Configuration
public
class
SecuritySecureConfig
extends
WebSecurityConfigurerAdapter
{
private
final
String
adminContextPath
;
private
final
String
adminContextPath
;
public
SecuritySecureConfig
(
AdminServerProperties
adminServerProperties
)
{
this
.
adminContextPath
=
adminServerProperties
.
getContextPath
();
}
public
SecuritySecureConfig
(
AdminServerProperties
adminServerProperties
)
{
this
.
adminContextPath
=
adminServerProperties
.
getContextPath
();
}
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
// @formatter:off
SavedRequestAwareAuthenticationSuccessHandler
successHandler
=
new
SavedRequestAwareAuthenticationSuccessHandler
();
successHandler
.
setTargetUrlParameter
(
"redirectTo"
);
successHandler
.
setDefaultTargetUrl
(
adminContextPath
+
"/"
);
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
// @formatter:off
SavedRequestAwareAuthenticationSuccessHandler
successHandler
=
new
SavedRequestAwareAuthenticationSuccessHandler
();
successHandler
.
setTargetUrlParameter
(
"redirectTo"
);
successHandler
.
setDefaultTargetUrl
(
adminContextPath
+
"/"
);
http
.
authorizeRequests
().
antMatchers
(
adminContextPath
+
"/assets/**"
).
permitAll
().
antMatchers
(
adminContextPath
+
"/login"
).
permitAll
().
anyRequest
().
authenticated
().
and
().
formLogin
().
loginPage
(
adminContextPath
+
"/login"
).
successHandler
(
successHandler
).
and
().
logout
().
logoutUrl
(
adminContextPath
+
"/logout"
).
and
().
httpBasic
().
and
().
csrf
().
csrfTokenRepository
(
CookieCsrfTokenRepository
.
withHttpOnlyFalse
()).
ignoringAntMatchers
(
adminContextPath
+
"/instances"
,
adminContextPath
+
"/actuator/**"
);
// @formatter:on
}
}
\ No newline at end of file
http
.
authorizeRequests
().
antMatchers
(
adminContextPath
+
"/assets/**"
).
permitAll
().
antMatchers
(
adminContextPath
+
"/login"
).
permitAll
().
anyRequest
().
authenticated
().
and
().
formLogin
().
loginPage
(
adminContextPath
+
"/login"
).
successHandler
(
successHandler
).
and
().
logout
().
logoutUrl
(
adminContextPath
+
"/logout"
).
and
().
httpBasic
().
and
().
csrf
().
csrfTokenRepository
(
CookieCsrfTokenRepository
.
withHttpOnlyFalse
()).
ignoringAntMatchers
(
adminContextPath
+
"/instances"
,
adminContextPath
+
"/actuator/**"
);
// @formatter:on
}
}
roncoo-education-util/src/main/resources/logback-roncoo.xml
浏览文件 @
c39e6792
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include
resource=
"org/springframework/boot/logging/logback/defaults.xml"
/>
<include
resource=
"org/springframework/boot/logging/logback/defaults.xml"
/>
<springProperty
name=
"springApplicationName"
source=
"spring.application.name"
defaultValue=
"roncoo-education"
/>
<springProperty
name=
"FILE_PATH"
source=
"management.endpoint.logfile.external-file"
defaultValue=
"/home/roncoo/logs"
/>
<springProperty
name=
"FILE_PATH"
source=
"management.endpoint.logfile.external-file"
defaultValue=
"/home/roncoo/logs"
/>
<property
name=
"PATTERN"
value=
"%-12(%d{yyyy-MM-dd HH:mm:ss.SSS}) |-%-5level [%thread] %c [%L] -| %msg%n"
/>
...
...
@@ -14,16 +15,16 @@
<pattern>
${PATTERN}
</pattern>
</encoder>
</appender>
<logger
name=
"com.roncoo"
level=
"debug"
/>
<logger
name=
"org.springframework.cloud.netflix.zuul"
level=
"debug"
/>
<logger
name=
"org.springframework.jdbc.core.JdbcTemplate"
level=
"debug"
/>
<logger
name=
"com.roncoo"
level=
"debug"
/>
<logger
name=
"org.springframework.cloud.netflix.zuul"
level=
"debug"
/>
<logger
name=
"org.springframework.jdbc.core.JdbcTemplate"
level=
"debug"
/>
<root
level=
"info"
>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"CONSOLE"
/>
</root>
</springProfile>
<!-- 开发、测试环境 -->
<springProfile
name=
"dev,test"
>
<springProfile
name=
"dev,test
,demo
"
>
<appender
name=
"CONSOLE"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<pattern>
${PATTERN}
</pattern>
...
...
@@ -44,13 +45,13 @@
</layout>
</appender>
<logger
name=
"com.roncoo"
level=
"debug"
/>
<logger
name=
"org.springframework.cloud.netflix.zuul"
level=
"debug"
/>
<logger
name=
"org.springframework.jdbc.core.JdbcTemplate"
level=
"debug"
/>
<logger
name=
"com.roncoo"
level=
"debug"
/>
<logger
name=
"org.springframework.cloud.netflix.zuul"
level=
"debug"
/>
<logger
name=
"org.springframework.jdbc.core.JdbcTemplate"
level=
"debug"
/>
<root
level=
"info"
>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"TEST-FILE"
/>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"TEST-FILE"
/>
</root>
</springProfile>
...
...
@@ -98,10 +99,10 @@
</encoder>
</appender>
<logger
name=
"com.roncoo"
level=
"warn"
/>
<logger
name=
"com.roncoo"
level=
"warn"
/>
<root
level=
"warn"
>
<appender-ref
ref=
"PROD_FILE"
/>
<appender-ref
ref=
"PROD_FILE"
/>
<!--<appender-ref ref="LOGSTASH" />-->
</root>
</springProfile>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录