main
周文涛 2 years ago
parent 2c551f3388
commit cd80a25daf

@ -175,6 +175,22 @@ public class ZxCelueServiceImpl extends ServiceImpl<ZxCelueMapper, ZxCelue> impl
List<String> collect = Arrays.stream(record.getDevid().split(",")).collect(Collectors.toList());
record.setDevidList(collect);
}
String xunhuanzhouqi="";
if (StringUtils.isNotBlank(record.getStartTime())) {
if(record.getStartTime().equals(record.getEndTime())){
//单日
xunhuanzhouqi=record.getStartTime();
}else{
//范围
xunhuanzhouqi=record.getStartTime()+"至"+record.getEndTime();
}
}
String s = CronLowUtil.cronToText(record.getTriggereTime());
xunhuanzhouqi= xunhuanzhouqi + " " + s;
if (!xunhuanzhouqi.contains("-") && !xunhuanzhouqi.contains("周")) {
xunhuanzhouqi="每天 "+xunhuanzhouqi;
}
record.setXunhuanzhouqi(xunhuanzhouqi);
}
return pageList;
}
@ -215,17 +231,12 @@ public class ZxCelueServiceImpl extends ServiceImpl<ZxCelueMapper, ZxCelue> impl
if (StringUtils.isNotBlank(zxCelue.getTriggereTime())) {
String[] s = zxCelue.getTriggereTime().split(" ");
String exeTime=null;
if (s.length==6) {
if (s.length>=6) {
//有秒
String s2 = new DecimalFormat("00").format(Integer.parseInt(s[2]));
String s1 = new DecimalFormat("00").format(Integer.parseInt(s[1]));
String s0 = new DecimalFormat("00").format(Integer.parseInt(s[0]));
exeTime=s2+":"+s1+":"+s0;
}else {
//没有秒
String s1 = new DecimalFormat("00").format(Integer.parseInt(s[1]));
String s0 = new DecimalFormat("00").format(Integer.parseInt(s[0]));
exeTime=s1+":"+s0+":00";
exeTime=s2+":"+s1/*+":"+s0*/;
}
zxCelueDTO.setExeTime(exeTime);
}

@ -3,8 +3,13 @@ package com.example.zxweb.utils;
import com.example.zxweb.common.constant.enums.WeekEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @Description Cron
@ -13,7 +18,8 @@ import java.text.DecimalFormat;
*/
public class CronLowUtil {
public static void main(String[] args) {
String timeType="everyDay";
System.out.println(cronToText("* * * * * 1,2 "));
/*String timeType="everyDay";
String exeTime="08:30";
String weeklyDay="1,2,3";//周一,周二,周三
String day="1,31";
@ -21,11 +27,10 @@ public class CronLowUtil {
String endDate="2023-09-30";//结束时间
System.out.println(getCron(timeType,exeTime,weeklyDay,day,startDate,endDate));
//cron转 显示文本
System.out.println(cronToText(getCron(timeType,exeTime,weeklyDay,day,startDate,endDate)));
System.out.println(cronToText(getCron(timeType,exeTime,weeklyDay,day,startDate,endDate)));*/
}
/**
*
* @param timeType (everyDay:,weekly:,day:,date:)
* @param exeTime (HH:mm 08:30)
* @param weeklyDay 1,2,3,
@ -34,42 +39,153 @@ public class CronLowUtil {
* @param endDate 2023-09-30
* @return cron
*/
public static String getCron(String timeType,String exeTime,String weeklyDay,String day,String startDate,String endDate) {
public static String getCron(String timeType, String exeTime, String weeklyDay, String day, String startDate, String endDate) {
String[] time = exeTime.split(":");
Integer hour=Integer.parseInt(time[0]);//小时
Integer minute=Integer.parseInt(time[1]);//分钟
Integer seconds=Integer.parseInt(time[2]);//秒
String cron=null;
Integer hour = Integer.parseInt(time[0]);//小时
Integer minute = Integer.parseInt(time[1]);//分钟
Integer seconds = 0;//Integer.parseInt(time[2]);//秒
String cron = null;
//每天
if ("everyDay".equals(timeType)) {
cron = String.format("%s %s %s * * ? *",seconds,minute,hour);
cron = String.format("%s %s %s * * ? *", seconds, minute, hour);
} else if ("weekly".equals(timeType)) {
//每周
cron = String.format("0 %s %s ? * %s",minute,hour,weeklyDay);
} else if("day".equals(timeType)){
cron = String.format("0 %s %s ? * %s", minute, hour, weeklyDay);
} else if ("day".equals(timeType)) {
//单日
cron = String.format("0 %s %s %s * ?",minute,hour,day);
} else if ("date".equals(timeType)){
cron = String.format("0 %s %s ? * ?", minute, hour/*, day*/);
} else if ("date".equals(timeType)) {
//日期段
System.out.println("在"+startDate+"到"+endDate);
cron = String.format("0 %s %s * * ? *",minute,hour);
System.out.println("在" + startDate + "到" + endDate);
cron = String.format("0 %s %s * * ? *", minute, hour);
}
return cron;
}
/**
* Cron
*
* @param cron cron
* @return
*/
public static String cronToText(String cron){
public static String cronToText(String cron) {
if (StringUtils.isBlank(cron)) {
return "未知";
}
StringBuilder sb=new StringBuilder();
StringBuilder sb = new StringBuilder();
String[] cronSplit = cron.split(" ");
for (int i = cronSplit.length-1; i >= 0;i--) {
List<String> years = null;//年
List<String> weeklys = null;//周
List<String> months = null;//月
List<String> days = null;//日
List<String> hours = null;//小时
List<String> minutes = null;//分钟
List<String> seconds = null;//秒
List<String> nots = Arrays.asList("?", "*");
if (cronSplit.length >= 7 && !nots.contains(cronSplit[6])) {
years = Arrays.asList(cronSplit[6].split(","));
}
if (cronSplit.length >= 6 && !nots.contains(cronSplit[5])) {
weeklys = Arrays.asList(cronSplit[5].split(","));
}
if (cronSplit.length >= 5 && !nots.contains(cronSplit[4])) {
months = Arrays.asList(cronSplit[4].split(","));
}
if (cronSplit.length >= 4 && !nots.contains(cronSplit[3])) {
days = Arrays.asList(cronSplit[3].split(","));
}
if (cronSplit.length >= 3 && !nots.contains(cronSplit[2])) {
hours = Arrays.asList(cronSplit[2].split(","));
}
if (cronSplit.length >= 2 && !nots.contains(cronSplit[1])) {
minutes = Arrays.asList(cronSplit[1].split(","));
}
if (cronSplit.length >= 1 && !nots.contains(cronSplit[0])) {
seconds = Arrays.asList(cronSplit[0].split(","));
}
//年
if (!CollectionUtils.isEmpty(years)) {
StringBuilder sb2 = new StringBuilder();
for (String year : years) {
sb2.append(year).append("年,");
}
if (sb2.length() > 0) {
sb.append(sb2.substring(0, sb2.length() - 1)).append(" ");
}
}
//周
if (!CollectionUtils.isEmpty(weeklys) ) {
StringBuilder sb2 = new StringBuilder();
for (String week : weeklys) {
sb2.append("周").append(NumberToCnUtil.toChineseLower(Integer.parseInt(week))).append(",");
}
if (sb2.length() > 0) {
sb.append(sb2.substring(0, sb2.length() - 1)).append(" ");
}
}
//月
if (!CollectionUtils.isEmpty(months)) {
StringBuilder sb2 = new StringBuilder();
for (String month : months) {
sb2.append(month).append("月").append(",");
}
if (sb2.length() > 0) {
sb.append(sb2.substring(0, sb2.length() - 1)).append(" ");
}
}
//日
if (!CollectionUtils.isEmpty(days)) {
StringBuilder sb2 = new StringBuilder();
for (String day : days) {
sb2.append(day).append("日").append(",");
}
if (sb2.length() > 0) {
sb.append(sb2.substring(0, sb2.length() - 1)).append(" ");
}
}
List<String> hhmmssList=new ArrayList<>();
//时
if (!CollectionUtils.isEmpty(hours)) {
for (String hour : hours) {
String hhmm=new DecimalFormat("00").format(Integer.parseInt(hour));
if (!CollectionUtils.isEmpty(minutes) && minutes.size()>0) {
for (String minute : minutes) {
hhmmssList.add(hhmm+":"+new DecimalFormat("00").format(Integer.parseInt(minute)));
}
}else{
hhmmssList.add(hhmm+":00");
}
}
}
sb.append(String.join(",",hhmmssList));
//判断是不是指定日
//0 0 8 1 1 ? 2019-2019 2019-01-01 08:00
/*if (cronSplit.length>=7) {
String[] years = cronSplit[6].split(",");
if (years.length==1) {
//单年
String year = years[0];
String[] months = cronSplit[4].split(",");
if (months.length==1) {
//月
String month = months[0];
String[] days = cronSplit[3].split(",");
if (days.length==1) {
String day = days[0];
String hour = cronSplit[2];
}
}
}else{
//多年
}
}*/
/*for (int i = cronSplit.length-1; i >= 0;i--) {
String c = cronSplit[i];
if (i==0) {
//秒
@ -78,12 +194,16 @@ public class CronLowUtil {
if (!"*".equals(c) && !"?".equals(c)) {
String[] split = c.split(",");
for (String s : split) {
sb.append(new DecimalFormat("00").format(Integer.parseInt(s))).append("");
sb.append(new DecimalFormat("00").format(Integer.parseInt(s)));
}
}else{
sb.append("00");
}
}else if(i==2){
//单天
if (sb.length()==0) {
sb.append("每天");
}
//小时
if (!"*".equals(c) && !"?".equals(c)) {
String[] split = c.split(",");
@ -97,7 +217,7 @@ public class CronLowUtil {
if (!"*".equals(c) && !"?".equals(c)) {
String[] split = c.split(",");
for (String s : split) {
daySb.append(s+"日").append(",");
daySb.append(s).append("日").append(",");
}
}
if (StringUtils.isNotBlank(daySb)) {
@ -110,28 +230,11 @@ public class CronLowUtil {
String[] split = c.split(",");
//sb.append("每周的 ");
for (String s : split) {
sb.append("周").append(NumberToCnUtil.toChineseLower(Integer.parseInt(s))).append(" ");
}
}
sb.append("周").append(NumberToCnUtil.toChineseLower(Integer.parseInt(s)));
}
}
for (int i = 0; i < cronSplit.length; i++) {
if (i==0) {
//秒
}else if(i==1){
//分钟
}else if(i==2){
//小时
}else if(i==3){
//天
}else if(i==4){//目前不需要做月
}else if(i==5){
//周
}else if(i==6){
//年 不需要
}
}
System.out.println(sb);
}*/
return sb.toString();
}

@ -112,6 +112,25 @@
.select2-container--default .select2-selection--multiple{
border: 1px solid #eee !important;
}
/* 设置只展示时分,隐藏秒那一列 */
.laydate-time-list {
padding-bottom: 0;
overflow: hidden;
}
.laydate-time-list > li {
width: 50% !important;
}
.laydate-time-list > li:last-child {
display: none;
}
.laydate-time-list ol li {
width: 100% !important;
padding-left: 0 !important;
text-align: center !important;
}
/* #1890ff-> #16b777*/
/*旧的颜色#16baaa*/
/*.layui-badge-rim, .layui-border, .layui-colla-content, .layui-colla-item, .layui-collapse, .layui-elem-field, .layui-form-pane .layui-form-item[pane], .layui-form-pane .layui-form-label, .layui-input, .layui-input-split, .layui-panel, .layui-quote-nm, .layui-select, .layui-tab-bar, .layui-tab-card, .layui-tab-title, .layui-tab-title .layui-this:after, .layui-textarea {
@ -261,7 +280,7 @@
<td>
<div class="layui-col-md3">
<div class="layui-input-wrap">
<input type="text" class="layui-input" id="ID-laydate-type-time" placeholder="选择策略开始时间" th:value="${detail.exeTime}">
<input type="text" class="layui-input laydate-time-list" id="ID-laydate-type-time" placeholder="选择策略开始时间" th:value="${detail.exeTime}">
<div class="layui-input-split layui-input-suffix" style="background-color: #f5f5f5">
<i class="layui-icon layui-icon-time"></i>
</div>
@ -352,7 +371,8 @@
});
laydate.render({
elem: '#ID-laydate-type-time',
type: 'time'
type: 'time',
format: 'HH:mm', //设置日期格式
});
// 日期范围 - 左右面板联动选择模式
laydate.render({
@ -529,6 +549,8 @@
});
return false;
}
startDate="";
endDate="";
}else if (timeType == 'day') {
if (checkNull(day)) {
layer.msg('请选择[选择日期]', {icon: 0}, function(){
@ -545,12 +567,16 @@
});
return false;
}
if(checkNull(startDate)&&checkNull(endDate)){
if(checkNull(endDate)){
layer.msg('请选择[策略执行结束日期]', {icon: 0}, function(){
// layer.msg('提示框关闭后的回调');
});
return false;
}
if (startDate == endDate) {
layer.msg('请选择[策略执行开始日期-结束日期 不可一致]', {icon: 0}, function(){});
return false;
}
}
if (checkNull(exeTime)) {
@ -567,8 +593,8 @@
'exeTime':exeTime,
'weeklyDay':weeklyDayList.join(','),
'day':day,
'starDate':startDate,
'endDate':endDate,
'startTime':startDate,
'endTime':endDate,
'description':description
};
let ajaxType='POST'//请求类型

Loading…
Cancel
Save