diff --git a/jero-boot/jero-cloud-module/jero-cloud-xxljob/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java b/jero-boot/jero-cloud-module/jero-cloud-xxljob/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java index 526c43b3..011518ad 100644 --- a/jero-boot/jero-cloud-module/jero-cloud-xxljob/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java +++ b/jero-boot/jero-cloud-module/jero-cloud-xxljob/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java @@ -40,18 +40,25 @@ public class XxlJobServiceImpl implements XxlJobService { private XxlJobLogGlueDao xxlJobLogGlueDao; @Resource private XxlJobLogReportDao xxlJobLogReportDao; - + + private String jobinfoFieldCronUnvalid ="jobinfo_field_cron_unvalid"; + private String systemPleaseInput ="system_please_input"; + private String jobinfoFieldChildJobId ="jobinfo_field_childJobId"; + private String systemUnvalid ="system_unvalid"; + private String systemNotFound ="system_not_found"; + private String zero ="({0})"; + @Override public Map pageList(int start, int length, int jobGroup, int triggerStatus, String jobDesc, String executorHandler, String author) { // page list List list = xxlJobInfoDao.pageList(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author); - int list_count = xxlJobInfoDao.pageListCount(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author); - + int listCount = xxlJobInfoDao.pageListCount(start, length, jobGroup, triggerStatus, jobDesc, executorHandler, author); + // package result - Map maps = new HashMap(); - maps.put("recordsTotal", list_count); // 总记录数 - maps.put("recordsFiltered", list_count); // 过滤后的总记录数 + Map maps = new HashMap<>(); + maps.put("recordsTotal", listCount); // 总记录数 + maps.put("recordsFiltered", listCount); // 过滤后的总记录数 maps.put("data", list); // 分页列表 return maps; } @@ -61,33 +68,33 @@ public class XxlJobServiceImpl implements XxlJobService { // valid XxlJobGroup group = xxlJobGroupDao.load(jobInfo.getJobGroup()); if (group == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose")+I18nUtil.getString("jobinfo_field_jobgroup")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_choose")+I18nUtil.getString("jobinfo_field_jobgroup")) ); } if (!CronExpression.isValidExpression(jobInfo.getJobCron())) { - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") ); + return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString(jobinfoFieldCronUnvalid) ); } if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+I18nUtil.getString("jobinfo_field_jobdesc")) ); } if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+I18nUtil.getString("jobinfo_field_author")) ); } if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString(systemUnvalid)) ); } if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString(systemUnvalid)) ); } if (GlueTypeEnum.match(jobInfo.getGlueType()) == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_gluetype")+I18nUtil.getString("system_unvalid")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_gluetype")+I18nUtil.getString(systemUnvalid)) ); } if (GlueTypeEnum.BEAN==GlueTypeEnum.match(jobInfo.getGlueType()) && (jobInfo.getExecutorHandler()==null || jobInfo.getExecutorHandler().trim().length()==0) ) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+"JobHandler") ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+"JobHandler") ); } // fix "\r" in shell if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(jobInfo.getGlueType()) && jobInfo.getGlueSource()!=null) { - jobInfo.setGlueSource(jobInfo.getGlueSource().replaceAll("\r", "")); + jobInfo.setGlueSource(jobInfo.getGlueSource().replace("\r", "")); } // ChildJobId valid @@ -97,23 +104,23 @@ public class XxlJobServiceImpl implements XxlJobService { if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) { XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.parseInt(childJobIdItem)); if (childJobInfo==null) { - return new ReturnT(ReturnT.FAIL_CODE, - MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem)); + return new ReturnT<>(ReturnT.FAIL_CODE, + MessageFormat.format((I18nUtil.getString(jobinfoFieldChildJobId)+zero+I18nUtil.getString(systemNotFound)), childJobIdItem)); } } else { - return new ReturnT(ReturnT.FAIL_CODE, - MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem)); + return new ReturnT<>(ReturnT.FAIL_CODE, + MessageFormat.format((I18nUtil.getString(jobinfoFieldChildJobId)+zero+I18nUtil.getString(systemUnvalid)), childJobIdItem)); } } // join , avoid "xxx,," - String temp = ""; + StringBuilder temp = new StringBuilder(); for (String item:childJobIds) { - temp += item + ","; + temp.append(item).append(","); } - temp = temp.substring(0, temp.length()-1); + temp = new StringBuilder(temp.substring(0, temp.length() - 1)); - jobInfo.setChildJobId(temp); + jobInfo.setChildJobId(temp.toString()); } // add in db @@ -122,15 +129,15 @@ public class XxlJobServiceImpl implements XxlJobService { jobInfo.setGlueUpdatetime(new Date()); xxlJobInfoDao.save(jobInfo); if (jobInfo.getId() < 1) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) ); } - return new ReturnT(String.valueOf(jobInfo.getId())); + return new ReturnT<>(String.valueOf(jobInfo.getId())); } private boolean isNumeric(String str){ try { - int result = Integer.valueOf(str); + Integer.valueOf(str); return true; } catch (NumberFormatException e) { return false; @@ -142,19 +149,19 @@ public class XxlJobServiceImpl implements XxlJobService { // valid if (!CronExpression.isValidExpression(jobInfo.getJobCron())) { - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") ); + return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString(jobinfoFieldCronUnvalid) ); } if (jobInfo.getJobDesc()==null || jobInfo.getJobDesc().trim().length()==0) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+I18nUtil.getString("jobinfo_field_jobdesc")) ); } if (jobInfo.getAuthor()==null || jobInfo.getAuthor().trim().length()==0) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString(systemPleaseInput)+I18nUtil.getString("jobinfo_field_author")) ); } if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString(systemUnvalid)) ); } if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString(systemUnvalid)) ); } // ChildJobId valid @@ -164,68 +171,68 @@ public class XxlJobServiceImpl implements XxlJobService { if (childJobIdItem!=null && childJobIdItem.trim().length()>0 && isNumeric(childJobIdItem)) { XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.parseInt(childJobIdItem)); if (childJobInfo==null) { - return new ReturnT(ReturnT.FAIL_CODE, - MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem)); + return new ReturnT<>(ReturnT.FAIL_CODE, + MessageFormat.format((I18nUtil.getString(jobinfoFieldChildJobId)+zero+I18nUtil.getString(systemNotFound)), childJobIdItem)); } } else { - return new ReturnT(ReturnT.FAIL_CODE, - MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem)); + return new ReturnT<>(ReturnT.FAIL_CODE, + MessageFormat.format((I18nUtil.getString(jobinfoFieldChildJobId)+zero+I18nUtil.getString(systemUnvalid)), childJobIdItem)); } } // join , avoid "xxx,," - String temp = ""; + StringBuilder temp = new StringBuilder(); for (String item:childJobIds) { - temp += item + ","; + temp.append(item).append(","); } - temp = temp.substring(0, temp.length()-1); + temp = new StringBuilder(temp.substring(0, temp.length() - 1)); - jobInfo.setChildJobId(temp); + jobInfo.setChildJobId(temp.toString()); } // group valid XxlJobGroup jobGroup = xxlJobGroupDao.load(jobInfo.getJobGroup()); if (jobGroup == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString("system_unvalid")) ); + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString(systemUnvalid)) ); } // stage job info - XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId()); - if (exists_jobInfo == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) ); + XxlJobInfo existsJobInfo = xxlJobInfoDao.loadById(jobInfo.getId()); + if (existsJobInfo == null) { + return new ReturnT<>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString(systemNotFound)) ); } // next trigger time (5s后生效,避开预读周期) - long nextTriggerTime = exists_jobInfo.getTriggerNextTime(); - if (exists_jobInfo.getTriggerStatus() == 1 && !jobInfo.getJobCron().equals(exists_jobInfo.getJobCron()) ) { + long nextTriggerTime = existsJobInfo.getTriggerNextTime(); + if (existsJobInfo.getTriggerStatus() == 1 && !jobInfo.getJobCron().equals(existsJobInfo.getJobCron()) ) { try { Date nextValidTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)); if (nextValidTime == null) { - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_never_fire")); + return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_never_fire")); } nextTriggerTime = nextValidTime.getTime(); } catch (ParseException e) { logger.error(e.getMessage(), e); - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage()); + return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString(jobinfoFieldCronUnvalid)+" | "+ e.getMessage()); } } - exists_jobInfo.setJobGroup(jobInfo.getJobGroup()); - exists_jobInfo.setJobCron(jobInfo.getJobCron()); - exists_jobInfo.setJobDesc(jobInfo.getJobDesc()); - exists_jobInfo.setAuthor(jobInfo.getAuthor()); - exists_jobInfo.setAlarmEmail(jobInfo.getAlarmEmail()); - exists_jobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy()); - exists_jobInfo.setExecutorHandler(jobInfo.getExecutorHandler()); - exists_jobInfo.setExecutorParam(jobInfo.getExecutorParam()); - exists_jobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy()); - exists_jobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout()); - exists_jobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount()); - exists_jobInfo.setChildJobId(jobInfo.getChildJobId()); - exists_jobInfo.setTriggerNextTime(nextTriggerTime); + existsJobInfo.setJobGroup(jobInfo.getJobGroup()); + existsJobInfo.setJobCron(jobInfo.getJobCron()); + existsJobInfo.setJobDesc(jobInfo.getJobDesc()); + existsJobInfo.setAuthor(jobInfo.getAuthor()); + existsJobInfo.setAlarmEmail(jobInfo.getAlarmEmail()); + existsJobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy()); + existsJobInfo.setExecutorHandler(jobInfo.getExecutorHandler()); + existsJobInfo.setExecutorParam(jobInfo.getExecutorParam()); + existsJobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy()); + existsJobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout()); + existsJobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount()); + existsJobInfo.setChildJobId(jobInfo.getChildJobId()); + existsJobInfo.setTriggerNextTime(nextTriggerTime); - exists_jobInfo.setUpdateTime(new Date()); - xxlJobInfoDao.update(exists_jobInfo); + existsJobInfo.setUpdateTime(new Date()); + xxlJobInfoDao.update(existsJobInfo); return ReturnT.SUCCESS; @@ -253,12 +260,12 @@ public class XxlJobServiceImpl implements XxlJobService { try { Date nextValidTime = new CronExpression(xxlJobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS)); if (nextValidTime == null) { - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_never_fire")); + return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_never_fire")); } nextTriggerTime = nextValidTime.getTime(); } catch (ParseException e) { logger.error(e.getMessage(), e); - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage()); + return new ReturnT<>(ReturnT.FAIL_CODE, I18nUtil.getString(jobinfoFieldCronUnvalid)+" | "+ e.getMessage()); } xxlJobInfo.setTriggerStatus(1); @@ -296,7 +303,7 @@ public class XxlJobServiceImpl implements XxlJobService { } // executor count - Set executorAddressSet = new HashSet(); + Set executorAddressSet = new HashSet<>(); List groupList = xxlJobGroupDao.findAll(); if (groupList!=null && !groupList.isEmpty()) { @@ -309,7 +316,7 @@ public class XxlJobServiceImpl implements XxlJobService { int executorCount = executorAddressSet.size(); - Map dashboardMap = new HashMap(); + Map dashboardMap = new HashMap<>(); dashboardMap.put("jobInfoCount", jobInfoCount); dashboardMap.put("jobLogCount", jobLogCount); dashboardMap.put("jobLogSuccessCount", jobLogSuccessCount); @@ -321,17 +328,17 @@ public class XxlJobServiceImpl implements XxlJobService { public ReturnT> chartInfo(Date startDate, Date endDate) { // process - List triggerDayList = new ArrayList(); - List triggerDayCountRunningList = new ArrayList(); - List triggerDayCountSucList = new ArrayList(); - List triggerDayCountFailList = new ArrayList(); + List triggerDayList = new ArrayList<>(); + List triggerDayCountRunningList = new ArrayList<>(); + List triggerDayCountSucList = new ArrayList<>(); + List triggerDayCountFailList = new ArrayList<>(); int triggerCountRunningTotal = 0; int triggerCountSucTotal = 0; int triggerCountFailTotal = 0; List logReportList = xxlJobLogReportDao.queryLogReport(startDate, endDate); - if (logReportList!=null && logReportList.size()>0) { + if (logReportList!=null && !logReportList.isEmpty()) { for (XxlJobLogReport item: logReportList) { String day = DateUtil.formatDate(item.getTriggerDay()); int triggerDayCountRunning = item.getRunningCount(); @@ -356,7 +363,7 @@ public class XxlJobServiceImpl implements XxlJobService { } } - Map result = new HashMap(); + Map result = new HashMap<>(); result.put("triggerDayList", triggerDayList); result.put("triggerDayCountRunningList", triggerDayCountRunningList); result.put("triggerDayCountSucList", triggerDayCountSucList); @@ -366,7 +373,7 @@ public class XxlJobServiceImpl implements XxlJobService { result.put("triggerCountSucTotal", triggerCountSucTotal); result.put("triggerCountFailTotal", triggerCountFailTotal); - return new ReturnT>(result); + return new ReturnT<>(result); } }