diff --git a/nacos_config.zip b/nacos_config.zip index ab8ab2b3d00d94cbea530ff6307ad70ea3ae7ae7..ae9a6be0b0775d5036f2744e73d8e7c00c23c8bb 100644 Binary files a/nacos_config.zip and b/nacos_config.zip differ diff --git a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/ServerGatewayApplication.java b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/ServerGatewayApplication.java index 0cdc2874a3037d3f6ed8ad941f92117347472f2a..1a352be11496fe0fc9e97f2cc7658e6b00e49cea 100644 --- a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/ServerGatewayApplication.java +++ b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/ServerGatewayApplication.java @@ -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); + } } diff --git a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/common/FilterPre.java b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/common/FilterPre.java similarity index 93% rename from roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/common/FilterPre.java rename to roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/common/FilterPre.java index bf13294aa1307f4593c341fdc7b9f1d618a83c75..c084c27d30acac6c8945896d5c89aecd0c2f4dbe 100644 --- a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/common/FilterPre.java +++ b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/common/FilterPre.java @@ -1,39 +1,36 @@ /** * 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 getParamMap(HttpServletRequest request) { + TreeMap paramMap = new TreeMap<>(); + Map 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 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 getParamMap(HttpServletRequest request) { - TreeMap paramMap = new TreeMap<>(); - Map 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 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; - } } diff --git a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/controller/HandlerController.java b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/controller/HandlerController.java new file mode 100644 index 0000000000000000000000000000000000000000..cb93927f20d77e044861be79bcb4c505d826d7eb --- /dev/null +++ b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/controller/HandlerController.java @@ -0,0 +1,39 @@ +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; + +@Slf4j +@RestController +public class HandlerController implements ErrorController { + + /** + * 出异常后进入该方法,交由下面的方法处理 + */ + @Override + public String getErrorPath() { + return "/error"; + } + + @RequestMapping("/error") + @ResponseStatus(HttpStatus.OK) + public Result 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); + } + +} diff --git a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/controller/IndexController.java b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/controller/IndexController.java similarity index 63% rename from roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/controller/IndexController.java rename to roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/controller/IndexController.java index 2cdce935834a728a6d96e8c275782d37c4a8ebee..54b817d549140e10d6f23821481d52808a3dbc9b 100644 --- a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/controller/IndexController.java +++ b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/controller/IndexController.java @@ -1,7 +1,7 @@ /** * 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"; + } } diff --git a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/controller/HandlerController.java b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/controller/HandlerController.java deleted file mode 100644 index 4fc8dd9da1dd5b01d1c6ee0f16bc1e63f40c2a8b..0000000000000000000000000000000000000000 --- a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/server/gateway/controller/HandlerController.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.roncoo.education.server.gateway.controller; - -import com.roncoo.education.util.base.Result; -import com.roncoo.education.util.enums.ResultEnum; -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; - -@RestController -public class HandlerController implements ErrorController { - - /** - * 出异常后进入该方法,交由下面的方法处理 - */ - @Override - public String getErrorPath() { - return "/error"; - } - - @RequestMapping("/error") - @ResponseStatus(HttpStatus.OK) - public Result 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); - } - -} diff --git a/roncoo-education-app-gateway/src/main/resources/bootstrap.properties b/roncoo-education-app-gateway/src/main/resources/bootstrap.properties index 31840108b91b62f44c5d6d59bcb79349d713b05b..40d0c8afc82cdc5f5070796e701385cc7a83e497 100644 --- a/roncoo-education-app-gateway/src/main/resources/bootstrap.properties +++ b/roncoo-education-app-gateway/src/main/resources/bootstrap.properties @@ -1,13 +1,13 @@ # application spring.application.name=roncoo-education-app-gateway # profile -spring.profiles.active=dev +spring.profiles.active=demo # 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} diff --git a/roncoo-education-app-gateway/src/main/resources/templates/index.ftl b/roncoo-education-app-gateway/src/main/resources/templates/index.ftl index e5fedaf1b4f372838ea745f0612ef7f73b55ab82..3679548ebb486346cdff69cc7bb7254407f1d34b 100644 --- a/roncoo-education-app-gateway/src/main/resources/templates/index.ftl +++ b/roncoo-education-app-gateway/src/main/resources/templates/index.ftl @@ -1,19 +1,19 @@ - - 接口文档 + + 接口文档 - diff --git a/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/MsgSendCrontab.java b/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/MsgSendCrontab.java new file mode 100644 index 0000000000000000000000000000000000000000..7b8d641bfacaac8730dae9419f2ba9d0055d20fc --- /dev/null +++ b/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/MsgSendCrontab.java @@ -0,0 +1,48 @@ +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; + +/** + * 站内信-定时发送 + * + * @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("站内信-定时发送-任务完成"); + } +} diff --git a/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/OrderCrontab.java b/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/OrderCrontab.java new file mode 100644 index 0000000000000000000000000000000000000000..eeabd0ac640d8f786487dd1cf43e07fba5b341c4 --- /dev/null +++ b/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/OrderCrontab.java @@ -0,0 +1,46 @@ +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; + +/** + * 定时任务-订单处理 + * + * @author wuyun + */ +@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; + } + +} diff --git a/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/VideoCrontab.java b/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/VideoCrontab.java new file mode 100644 index 0000000000000000000000000000000000000000..5f8c2de9790703c263962dd1f2fda38b53edf273 --- /dev/null +++ b/roncoo-education-app-job/src/main/java/com/roncoo/education/app/job/VideoCrontab.java @@ -0,0 +1,68 @@ +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; + + /** + * 定时任务每分钟执行一次
+ * 注意:每个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); + } + +} diff --git a/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/MsgSendCrontab.java b/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/MsgSendCrontab.java deleted file mode 100644 index 63a4db99f60dcdd1633f4cb160806ec2bdf3f7d3..0000000000000000000000000000000000000000 --- a/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/MsgSendCrontab.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.roncoo.education.server.job; - -import com.roncoo.education.system.feign.interfaces.IFeignMsg; -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("站内信-定时发送-任务完成"); - } -} diff --git a/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/OrderCrontab.java b/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/OrderCrontab.java deleted file mode 100644 index 256eaf39bd6fa961ae65ef4a08bbec8620b90c8a..0000000000000000000000000000000000000000 --- a/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/OrderCrontab.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.roncoo.education.server.job; - -import com.roncoo.education.course.feign.interfaces.IFeignOrderInfo; -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 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; - } - -} diff --git a/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/VideoCrontab.java b/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/VideoCrontab.java deleted file mode 100644 index 0115414874355daecf4c3ec9e8d0e50136be07d9..0000000000000000000000000000000000000000 --- a/roncoo-education-app-job/src/main/java/com/roncoo/education/server/job/VideoCrontab.java +++ /dev/null @@ -1,69 +0,0 @@ -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; - - /** - * 定时任务每分钟执行一次
- * 注意:每个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); - } - -} diff --git a/roncoo-education-app-sba/src/main/java/com/roncoo/education/server/sba/ServerSbaApplication.java b/roncoo-education-app-sba/src/main/java/com/roncoo/education/app/sba/ServerSbaApplication.java similarity index 74% rename from roncoo-education-app-sba/src/main/java/com/roncoo/education/server/sba/ServerSbaApplication.java rename to roncoo-education-app-sba/src/main/java/com/roncoo/education/app/sba/ServerSbaApplication.java index adb51c01d0144182466c8a4435f734678a531490..e70e681a56f3bb1fbf50c3217cd22691243a77d8 100644 --- a/roncoo-education-app-sba/src/main/java/com/roncoo/education/server/sba/ServerSbaApplication.java +++ b/roncoo-education-app-sba/src/main/java/com/roncoo/education/app/sba/ServerSbaApplication.java @@ -1,21 +1,20 @@ /** * 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); + } } diff --git a/roncoo-education-app-sba/src/main/java/com/roncoo/education/app/sba/config/SecuritySecureConfig.java b/roncoo-education-app-sba/src/main/java/com/roncoo/education/app/sba/config/SecuritySecureConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..b34cd9fe6ce90250de584f9f83f4bde5642a513c --- /dev/null +++ b/roncoo-education-app-sba/src/main/java/com/roncoo/education/app/sba/config/SecuritySecureConfig.java @@ -0,0 +1,28 @@ +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; + +@Configuration +public class SecuritySecureConfig extends WebSecurityConfigurerAdapter { + private final String adminContextPath; + + 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 + "/"); + + 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 + } +} diff --git a/roncoo-education-app-sba/src/main/java/com/roncoo/education/server/sba/config/SecuritySecureConfig.java b/roncoo-education-app-sba/src/main/java/com/roncoo/education/server/sba/config/SecuritySecureConfig.java deleted file mode 100644 index 4f4a0573726779ba04ab6be5e4282a6a9d5a5f4c..0000000000000000000000000000000000000000 --- a/roncoo-education-app-sba/src/main/java/com/roncoo/education/server/sba/config/SecuritySecureConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.roncoo.education.server.sba.config; - -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; - - 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 + "/"); - - 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 diff --git a/roncoo-education-util/src/main/resources/logback-roncoo.xml b/roncoo-education-util/src/main/resources/logback-roncoo.xml index a5d290dae239e0c15ec2ca8b8f78039aa7342308..8c965431dac50464315b41bf958aed2cc27f91f3 100644 --- a/roncoo-education-util/src/main/resources/logback-roncoo.xml +++ b/roncoo-education-util/src/main/resources/logback-roncoo.xml @@ -1,9 +1,10 @@ - + - + @@ -14,16 +15,16 @@ ${PATTERN} - - - + + + - + - + ${PATTERN} @@ -44,13 +45,13 @@ - - - + + + - - + + @@ -98,10 +99,10 @@ - + - +