From 2019e06fbbefc3e924009db12b26a667a126ab96 Mon Sep 17 00:00:00 2001 From: zhouwentao <1577701412@qq.com> Date: Fri, 15 Sep 2023 18:02:53 +0800 Subject: [PATCH] updates --- .../zxweb/controller/CelueController.java | 4 +- .../com/example/zxweb/dto/ZxCelueDTO.java | 2 + .../service/impl/ZxCelueServiceImpl.java | 12 + .../com/example/zxweb/utils/CronLowUtil.java | 3 +- src/main/resources/templates/add.html | 251 +++++++++++------- src/main/resources/templates/index.html | 17 +- 6 files changed, 183 insertions(+), 106 deletions(-) diff --git a/src/main/java/com/example/zxweb/controller/CelueController.java b/src/main/java/com/example/zxweb/controller/CelueController.java index b3fcb0c..05a40df 100644 --- a/src/main/java/com/example/zxweb/controller/CelueController.java +++ b/src/main/java/com/example/zxweb/controller/CelueController.java @@ -54,14 +54,14 @@ public class CelueController { @PostMapping public Result add(@RequestBody AddZxCeluePVO addZxCeluePVO){ zxCelueService.saveZxCelue(addZxCeluePVO); - return Result.OK(); + return Result.OK("操作成功"); } @ApiOperation(value = "编辑") @PutMapping public Resultedit(@RequestBody ZxCelue zxCelue){ zxCelueService.updateById(zxCelue); - return Result.OK(); + return Result.OK("操作成功"); } @ApiOperation(value = "编辑状态") diff --git a/src/main/java/com/example/zxweb/dto/ZxCelueDTO.java b/src/main/java/com/example/zxweb/dto/ZxCelueDTO.java index 3fea940..727977b 100644 --- a/src/main/java/com/example/zxweb/dto/ZxCelueDTO.java +++ b/src/main/java/com/example/zxweb/dto/ZxCelueDTO.java @@ -21,4 +21,6 @@ public class ZxCelueDTO extends ZxCelue { private String timeType; @ApiModelProperty(value = "每周") private String weeklyDay; + @ApiModelProperty(value = "执行时段") + private String exeTime; } diff --git a/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java b/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java index d5e1a93..4567dd2 100644 --- a/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java +++ b/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java @@ -32,6 +32,9 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; @@ -203,6 +206,15 @@ public class ZxCelueServiceImpl extends ServiceImpl impl } } } + //获取执行时段 + if (StringUtils.isNotBlank(zxCelue.getTriggereTime())) { + String[] s = zxCelue.getTriggereTime().split(" "); + 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])); + String exeTime=s2+":"+s1+":"+s0; + zxCelueDTO.setExeTime(exeTime); + } return zxCelueDTO; } diff --git a/src/main/java/com/example/zxweb/utils/CronLowUtil.java b/src/main/java/com/example/zxweb/utils/CronLowUtil.java index 565f81f..a4ef66d 100644 --- a/src/main/java/com/example/zxweb/utils/CronLowUtil.java +++ b/src/main/java/com/example/zxweb/utils/CronLowUtil.java @@ -38,10 +38,11 @@ public class CronLowUtil { 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; //每天 if ("everyDay".equals(timeType)) { - cron = String.format("0 %s %s * * ? *",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); diff --git a/src/main/resources/templates/add.html b/src/main/resources/templates/add.html index a995394..bcd8457 100644 --- a/src/main/resources/templates/add.html +++ b/src/main/resources/templates/add.html @@ -8,8 +8,8 @@ - + @@ -145,7 +145,8 @@
- + +
@@ -173,18 +174,13 @@
- +
-
-
- 开灯/放电 - 关灯/断电 -
-
@@ -192,7 +188,8 @@ 执行周期:
- + + @@ -200,7 +197,7 @@
- + 选择日期: @@ -221,13 +218,13 @@ - + 选择日期:
- +
@@ -235,14 +232,14 @@
- + 选择日期:
- +
@@ -250,7 +247,7 @@
- +
@@ -264,7 +261,7 @@
- +
@@ -277,7 +274,7 @@
- +
@@ -285,11 +282,12 @@
- +
- + +
@@ -303,16 +301,43 @@ var name=''; var status=''; getDeviceList() - - - /*select2 回显*/ - var str=$("#devids").val(); - var arr=str.split(','); - console.log(arr) - $('#id_select2_demo1').val(arr).trigger('change') - + function getDeviceList(){ + $.ajax({ + type: "GET", + url: "/device/listAll", + success: function(res){ + console.log(res) + if(res.success){ + var selectorx = $('#id_select2_demo1').select2(); + //var data=[{"id":"1","text":"1F左侧走廊照明灯组"},{"id":2,"text":"1F右侧走廊照明灯组"},{"id":3,"text":"2F左侧走廊照明灯组"},{"id":4,"text":"2F右侧走廊照明灯组"}]; + $("#id_select2_demo1").select2({ + data:res.result + }); + changeSelect() + }else{} + } + }); + } + function changeSelect(){ + /*select2 回显*/ + var str=$("#devids").val(); + var arr=str.split(','); + console.log(arr) + var select2d = $("#id_select2_demo1").select2(); + select2d.val(arr).trigger('change') + } loadTable(); var form; + + /*详情页,加载列表颜色*/ + var timeTypeValue = $("#timeTypeValue").val(); + if(timeTypeValue!=null &&timeTypeValue!=undefined &&timeTypeValue!=''){ + rowColor(timeTypeValue) + }else{ + /*新增页,默认每天*/ + rowColor('everyDay') + } + function loadTable(){ layui.use('table', function () { var table = layui.table; @@ -341,6 +366,7 @@ /*$('#dayTr').hide(); $('#dayTr2').show();*/ + //周 回显 let weeklyd = $("#weeklyd").val(); if (weeklyd != null && weeklyd != '') { let split = weeklyd.split(','); @@ -352,11 +378,21 @@ } form.render(); }); - /*for (let i = 0; i < split.length; i++) { - console.log(split[i]) - $("#weeklyDay"+split[i]).attr("checked","checked"); - }*/ } + //操作类型 回显 + $("#type").each(function (){ + var typeValue=$("#typeValue").val(); + // this代表的是,对option再进行遍历 + $(this).children("option").each(function() { + // 判断需要对那个选项进行回显 + if (this.value == typeValue) { + console.log($(this).text()); + // 进行回显 + $(this).attr("selected","selected"); + } + }); + form.render(); + }) // 事件 // radio 事件 @@ -366,7 +402,6 @@ var value = elem.value; // 获得 radio 值 var othis = data.othis; // 获得 radio 元素被替换后的 jQuery 对象 - var i=0; console.log(value) if(value=='weekly'){ $("#weeklyTr").show(); @@ -385,38 +420,56 @@ $("#dayTr").hide(); $("#dateTr").hide(); } - - /*if (value == 'day') { - $('#dayTr').show(); - $("#dayTr2").hide(); - $('tr').each(function(i) { - i++; - if(i % 2 ==0){ - $(this).css("background","#f5f5f5"); - }else{ - $(this).css("background",''); - } - }); - }else{ - $('#dayTr').hide(); - $('#dayTr2').show(); - $('tr').each(function() { - if ($(this).attr('id') != 'dayTr') { - i++; - if (i % 2 == 0) { - $(this).css("background", "#f5f5f5"); - } else { - $(this).css("background", ''); - } - } - }) - }*/ - + rowColor(value) }); }); }; - function sub(){ + function rowColor(value){ + var i=0; + $('tr').each(function(i) { + $(this).css("background", ''); + }); + //选择每天 + if (value == 'day') { + $('tr').each(function(i) { + if ($(this).attr('id') != 'dayTr') { + i++; + if (i % 2 == 0) { + $(this).css("background", "#f5f5f5"); + } + } + }); + }else if(value =='weekly'){ + $('tr').each(function(i) { + i++; + if(i % 2 ==0){ + $(this).css("background","#f5f5f5"); + } + }); + }else if(value == 'everyDay'){ + $('tr').each(function() { + if ($(this).attr('id') != 'dayTr') { + i++; + if (i % 2 == 0) { + $(this).css("background", "#f5f5f5"); + } + } + }) + } else{ + $('tr').each(function() { + i++; + if ($(this).attr('id') != 'dateTr') { + if (i % 2 == 0) { + $(this).css("background", "#f5f5f5"); + } + } + + }) + } + } + + function sub(subType){ //策略名称 let celueName = $("#celueName").val(); //选择设备 @@ -495,35 +548,56 @@ } var index = layer.load(0, {shade: false}); + var obj = { + 'name':celueName, + 'devidList':devidList, + 'type':type, + 'timeType':timeType, + 'exeTime':exeTime, + 'weeklyDay':weeklyDayList.join(','), + 'day':day, + 'starDate':startDate, + 'endDate':endDate, + 'description':description + }; + let ajaxType='POST'//请求类型 + if (subType == 'edit') { + obj.celueid = $("#celueid").val() + ajaxType = 'PUT' + } //请求保存 - var obj = JSON.stringify({ - 'name':celueName, - 'devidList':devidList, - 'type':type, - 'timeType':timeType, - 'exeTime':exeTime, - 'weeklyDay':weeklyDayList.join(','), - 'day':day, - 'starDate':startDate, - 'endDate':endDate, - 'description':description - }); + var jsonObj = JSON.stringify(obj); + console.log(jsonObj) $.ajax({ - type: "POST", + type: ajaxType, url: "/celue", - data: obj, + data: jsonObj, contentType: 'application/json;charset=utf-8', success: function(res){ console.log(res) layer.close(index); if (res.success) { - layer.msg(res.message, {icon: 0}); + layer.alert(res.message, { + time: 2*1000, + success: function(layero, index){ + var timeNum = this.time/1000, setText = function(start){ + layer.title(''+ (start ? timeNum : --timeNum) + ' 秒后自动关闭', index); + }; + setText(!0); + this.timer = setInterval(setText, 1000); + if(timeNum <= 0) clearInterval(this.timer); + }, + end: function(){ + clearInterval(this.timer); + window.location.href='/'; + } + }); }else{ - layer.msg(res.message, {icon: 0}); + layer.msg(res.message, {icon: 0,title:'提示'}); } },error:function (res){ layer.close(index); - layer.msg(res.message, {icon: 0}); + layer.msg(res.message, {icon: 0,title:'提示'}); } }); setTimeout(function(){ @@ -544,25 +618,8 @@ } return false; } - function getDeviceList(){ - $.ajax({ - type: "GET", - url: "/device/listAll", - /*data: obj, - contentType: 'application/json;charset=utf-8',*/ - success: function(res){ - console.log(res) - if(res.success){ - var selectorx = $('#id_select2_demo1').select2(); - $("#id_select2_demo1").select2({ - data:res.result - }); - }else{ - } - },error:function (res){ - /*layer.msg('删除失败,'+res.message, {icon: 1});*/ - } - }); + function back(){ + window.location.href='/'; } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 325f38d..c354097 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -102,7 +102,7 @@
- +
@@ -125,7 +125,7 @@