From 7ccdd75d4a3fcd753301a7dea641666e77b4c8fa Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Sat, 4 May 2019 23:43:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86=EF=BC=9A?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=99=A8=E7=BB=B4=E5=BA=A6=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6=EF=BC=8C=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E6=8B=A5=E6=9C=89=E5=85=A8=E9=87=8F=E6=9D=83=E9=99=90?= =?UTF-8?q?=EF=BC=8C=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=88=86=E9=85=8D=E6=89=A7=E8=A1=8C=E5=99=A8=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=90=8E=E6=89=8D=E5=85=81=E8=AE=B8=E7=9B=B8=E5=85=B3=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/JobInfoController.java | 37 +++++++++++++++++-- .../admin/controller/JobLogController.java | 36 +++++++++++++++--- .../resolver/WebExceptionResolver.java | 6 ++- .../admin/core/exception/XxlJobException.java | 14 +++++++ .../src/main/resources/application.properties | 5 --- .../main/resources/i18n/message.properties | 1 + .../main/resources/i18n/message_en.properties | 1 + 7 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 xxl-job-admin/src/main/java/com/xxl/job/admin/core/exception/XxlJobException.java diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java index d41933c1..59e59d0d 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java @@ -1,22 +1,30 @@ package com.xxl.job.admin.controller; +import com.xxl.job.admin.core.exception.XxlJobException; import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; +import com.xxl.job.admin.core.model.XxlJobUser; import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum; import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; import com.xxl.job.admin.core.trigger.TriggerTypeEnum; +import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.dao.XxlJobGroupDao; +import com.xxl.job.admin.service.LoginService; import com.xxl.job.admin.service.XxlJobService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; import com.xxl.job.core.glue.GlueTypeEnum; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -34,15 +42,38 @@ public class JobInfoController { private XxlJobService xxlJobService; @RequestMapping - public String index(Model model, @RequestParam(required = false, defaultValue = "-1") int jobGroup) { + public String index(HttpServletRequest request, Model model, @RequestParam(required = false, defaultValue = "-1") int jobGroup) { // 枚举-字典 model.addAttribute("ExecutorRouteStrategyEnum", ExecutorRouteStrategyEnum.values()); // 路由策略-列表 model.addAttribute("GlueTypeEnum", GlueTypeEnum.values()); // Glue类型-字典 model.addAttribute("ExecutorBlockStrategyEnum", ExecutorBlockStrategyEnum.values()); // 阻塞处理策略-字典 - // 任务组 - List jobGroupList = xxlJobGroupDao.findAll(); + // 执行器列表 + List jobGroupList_all = xxlJobGroupDao.findAll(); + + // filter group + List jobGroupList = new ArrayList<>(); + if (jobGroupList_all!=null && jobGroupList_all.size()>0) { + XxlJobUser loginUser = (XxlJobUser) request.getAttribute(LoginService.LOGIN_IDENTITY_KEY); + if (loginUser.getRole() == 1) { + jobGroupList = jobGroupList_all; + } else { + List groupIdStrs = new ArrayList<>(); + if (loginUser.getPermission()!=null && loginUser.getPermission().trim().length()>0) { + groupIdStrs = Arrays.asList(loginUser.getPermission().trim().split(",")); + } + for (XxlJobGroup groupItem:jobGroupList_all) { + if (groupIdStrs.contains(String.valueOf(groupItem.getId()))) { + jobGroupList.add(groupItem); + } + } + } + } + if (jobGroupList==null || jobGroupList.size()==0) { + throw new XxlJobException(I18nUtil.getString("jobgroup_empty")); + } + model.addAttribute("JobGroupList", jobGroupList); model.addAttribute("jobGroup", jobGroup); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java index 2a50b633..5fc53b6e 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java @@ -1,13 +1,16 @@ package com.xxl.job.admin.controller; +import com.xxl.job.admin.core.exception.XxlJobException; import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; +import com.xxl.job.admin.core.model.XxlJobUser; import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.dao.XxlJobGroupDao; import com.xxl.job.admin.dao.XxlJobInfoDao; import com.xxl.job.admin.dao.XxlJobLogDao; +import com.xxl.job.admin.service.LoginService; import com.xxl.job.core.biz.ExecutorBiz; import com.xxl.job.core.biz.model.LogResult; import com.xxl.job.core.biz.model.ReturnT; @@ -21,11 +24,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.text.ParseException; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * index controller @@ -44,10 +45,33 @@ public class JobLogController { public XxlJobLogDao xxlJobLogDao; @RequestMapping - public String index(Model model, @RequestParam(required = false, defaultValue = "0") Integer jobId) { + public String index(HttpServletRequest request, Model model, @RequestParam(required = false, defaultValue = "0") Integer jobId) { // 执行器列表 - List jobGroupList = xxlJobGroupDao.findAll(); + List jobGroupList_all = xxlJobGroupDao.findAll(); + + // filter group + List jobGroupList = new ArrayList<>(); + if (jobGroupList_all!=null && jobGroupList_all.size()>0) { + XxlJobUser loginUser = (XxlJobUser) request.getAttribute(LoginService.LOGIN_IDENTITY_KEY); + if (loginUser.getRole() == 1) { + jobGroupList = jobGroupList_all; + } else { + List groupIdStrs = new ArrayList<>(); + if (loginUser.getPermission()!=null && loginUser.getPermission().trim().length()>0) { + groupIdStrs = Arrays.asList(loginUser.getPermission().trim().split(",")); + } + for (XxlJobGroup groupItem:jobGroupList_all) { + if (groupIdStrs.contains(String.valueOf(groupItem.getId()))) { + jobGroupList.add(groupItem); + } + } + } + } + if (jobGroupList==null || jobGroupList.size()==0) { + throw new XxlJobException(I18nUtil.getString("jobgroup_empty")); + } + model.addAttribute("JobGroupList", jobGroupList); // 任务 diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/resolver/WebExceptionResolver.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/resolver/WebExceptionResolver.java index e2e0f27a..a0b3e6a6 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/resolver/WebExceptionResolver.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/resolver/WebExceptionResolver.java @@ -1,5 +1,6 @@ package com.xxl.job.admin.controller.resolver; +import com.xxl.job.admin.core.exception.XxlJobException; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.admin.core.util.JacksonUtil; import org.slf4j.Logger; @@ -26,7 +27,10 @@ public class WebExceptionResolver implements HandlerExceptionResolver { @Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { - logger.error("WebExceptionResolver:{}", ex); + + if (!(ex instanceof XxlJobException)) { + logger.error("WebExceptionResolver:{}", ex); + } // if json boolean isJson = false; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/exception/XxlJobException.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/exception/XxlJobException.java new file mode 100644 index 00000000..faa6063c --- /dev/null +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/exception/XxlJobException.java @@ -0,0 +1,14 @@ +package com.xxl.job.admin.core.exception; + +/** + * @author xuxueli 2019-05-04 23:19:29 + */ +public class XxlJobException extends RuntimeException { + + public XxlJobException() { + } + public XxlJobException(String message) { + super(message); + } + +} diff --git a/xxl-job-admin/src/main/resources/application.properties b/xxl-job-admin/src/main/resources/application.properties index b528d8e6..3d13f9a2 100644 --- a/xxl-job-admin/src/main/resources/application.properties +++ b/xxl-job-admin/src/main/resources/application.properties @@ -38,11 +38,6 @@ spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.required=true - -### xxl-job login -xxl.job.login.username=admin -xxl.job.login.password=123456 - ### xxl-job, access token xxl.job.accessToken= diff --git a/xxl-job-admin/src/main/resources/i18n/message.properties b/xxl-job-admin/src/main/resources/i18n/message.properties index 0a377201..12200909 100644 --- a/xxl-job-admin/src/main/resources/i18n/message.properties +++ b/xxl-job-admin/src/main/resources/i18n/message.properties @@ -194,6 +194,7 @@ jobgroup_field_order_digits=请输入整数 jobgroup_field_orderrange=取值范围为1~1000 jobgroup_del_limit_0=拒绝删除,该执行器使用中 jobgroup_del_limit_1=拒绝删除, 系统至少保留一个执行器 +jobgroup_empty=不存在有效执行器,请联系管理员 ## job conf jobconf_block_SERIAL_EXECUTION=单机串行 diff --git a/xxl-job-admin/src/main/resources/i18n/message_en.properties b/xxl-job-admin/src/main/resources/i18n/message_en.properties index 3797645a..d642220d 100644 --- a/xxl-job-admin/src/main/resources/i18n/message_en.properties +++ b/xxl-job-admin/src/main/resources/i18n/message_en.properties @@ -194,6 +194,7 @@ jobgroup_field_order_digits=Please enter a positive integer jobgroup_field_orderrange=Order is limited to 1~1000 jobgroup_del_limit_0=Refuse to delete, the executor is being used jobgroup_del_limit_1=Refuses to delete, the system retains at least one executor +jobgroup_empty=There is no valid executor. Please contact the administrator ## job conf jobconf_block_SERIAL_EXECUTION=Serial execution