main
周文涛 2 years ago
parent ae3b3503c1
commit 2019e06fbb

@ -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 Result<?>edit(@RequestBody ZxCelue zxCelue){
zxCelueService.updateById(zxCelue);
return Result.OK();
return Result.OK("操作成功");
}
@ApiOperation(value = "编辑状态")

@ -21,4 +21,6 @@ public class ZxCelueDTO extends ZxCelue {
private String timeType;
@ApiModelProperty(value = "每周")
private String weeklyDay;
@ApiModelProperty(value = "执行时段")
private String exeTime;
}

@ -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<ZxCelueMapper, ZxCelue> 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;
}

@ -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);

@ -8,8 +8,8 @@
<!-- 引入 layui.css -->
<link href="../static/layui-v2.8.11/css/layui.css" rel="stylesheet">
<!-- 引入 layui.js -->
<script src="../static/layui-v2.8.11/layui.js"></script>
<script src="../static/jquery/jquery-3.2.1.min.js"></script>
<script src="../static/layui-v2.8.11/layui.js"></script>
<!-- 加载 Select2 -->
<link href="../static/select2/4.0.8/css/select2.min.css" rel="stylesheet" />
<script src="../static/select2/4.0.8/js/select2.min.js"></script>
@ -145,7 +145,8 @@
<td>
<div class="layui-col-md7">
<div class="layui-form">
<input type="text" name="name" id="celueName" placeholder="请填写策略名称···" class="layui-input" th:value="${detail.name}" th:readonly="${type=='detail'}">
<input type="hidden" th:value="${detail.celueid}" id="celueid"/>
<input type="text" name="name" id="celueName" placeholder="请填写策略名称···" class="layui-input" th:value="${detail.name}">
</div>
</div>
</td>
@ -173,18 +174,13 @@
<td>
<div class="layui-form layui-row layui-col-space16">
<div class="layui-col-md3">
<select id="type" th:value="${detail.type}" th:readonly="${type=='detail'}" th:if="${type!='detail'}">
<input type="hidden" th:value="${detail.type}" id="typeValue"/>
<select id="type" th:readonly="${type=='detail'}">
<option value="">请选择</option>
<option value="1">开灯/放电</option>
<option value="0">关灯/断电</option>
</select>
</div>
<div th:else th:switch="${detail.type}">
<div class="layui-field-box">
<span th:case="1">开灯/放电</span>
<span th:case="0">关灯/断电</span>
</div>
</div>
</div>
</td>
</tr>
@ -192,7 +188,8 @@
<td>执行周期:</td>
<td>
<div class="layui-form">
<input type="radio" name="timeType" value="everyDay" lay-filter="demo-radio-filter" title="每天" th:checked="${detail.timeType=='everyDay'}">
<input type="hidden" id="timeTypeValue" th:value="${detail.timeType}"/>
<input type="radio" name="timeType" value="everyDay" lay-filter="demo-radio-filter" title="每天" th:checked="${detail.timeType=='everyDay' || type == 'add'}">
<input type="radio" name="timeType" value="weekly" lay-filter="demo-radio-filter" title="每周" th:checked="${detail.timeType=='weekly'}">
<input type="radio" name="timeType" value="day" lay-filter="demo-radio-filter" title="单日" th:checked="${detail.timeType=='day'}">
<input type="radio" name="timeType" value="date" lay-filter="demo-radio-filter" title="日期段" th:checked="${detail.timeType=='date'}">
@ -200,7 +197,7 @@
</div>
</td>
</tr>
<tr id="weeklyTr" th:hidden="${type=='add' && detail.timeType!='weekly'}">
<tr id="weeklyTr" th:hidden="${type=='add' || detail.timeType!='weekly'}">
<!---->
<td>选择日期:</td>
<td>
@ -221,13 +218,13 @@
</div>
</td>
</tr>
<tr id="dayTr" th:hidden="${type=='add' && detail.timeType!='day'}">
<tr id="dayTr" th:hidden="${type=='add' || detail.timeType!='day'}">
<!--单日-->
<td>选择日期:</td>
<td>
<div class="layui-col-md3" id="dayDiv">
<div class="layui-input-wrap">
<input type="text" class="layui-input" id="ID-laydate-demo" placeholder="选择策略执行时间">
<input type="text" class="layui-input" id="ID-laydate-demo" placeholder="选择策略执行时间" th:value="${detail.startTime}">
<div class="layui-input-split layui-input-suffix" style="background-color: #f5f5f5">
<i class="layui-icon layui-icon-time"></i>
</div>
@ -235,14 +232,14 @@
</div>
</td>
</tr>
<tr id="dateTr" th:hidden="${type=='add' && detail.timeType!='date'}">
<tr id="dateTr" th:hidden="${type=='add' || detail.timeType!='date'}">
<!--范围-->
<td>选择日期:</td>
<td>
<div id="ID-laydate-rangeLinked">
<div class="layui-col-md3" style="margin-right: 0.5%">
<div class="layui-input-wrap">
<input type="text" autocomplete="off" id="ID-laydate-start-date-1" class="layui-input" placeholder="选择策略执行开始日期">
<input type="text" autocomplete="off" id="ID-laydate-start-date-1" class="layui-input" placeholder="选择策略执行开始日期" th:value="${detail.startTime}">
<div class="layui-input-split layui-input-suffix" style="background-color: #f5f5f5">
<i class="layui-icon layui-icon-date"></i>
</div>
@ -250,7 +247,7 @@
</div>
<div class="layui-col-md3">
<div class="layui-input-wrap">
<input type="text" autocomplete="off" id="ID-laydate-end-date-1" class="layui-input" placeholder="选择策略执行结束日期">
<input type="text" autocomplete="off" id="ID-laydate-end-date-1" class="layui-input" placeholder="选择策略执行结束日期" th:value="${detail.endTime}">
<div class="layui-input-split layui-input-suffix" style="background-color: #f5f5f5">
<i class="layui-icon layui-icon-date"></i>
</div>
@ -264,7 +261,7 @@
<td>
<div class="layui-col-md3">
<div class="layui-input-wrap">
<input type="text" class="layui-input" id="ID-laydate-type-time" placeholder="选择策略开始时间">
<input type="text" class="layui-input" 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>
@ -277,7 +274,7 @@
<td>
<div class="layui-col-md7">
<div class="layui-form">
<textarea name="detail" id="detail" placeholder="请填写备注文字···" class="layui-textarea"></textarea>
<textarea name="detail" id="detail" placeholder="请填写备注文字···" class="layui-textarea" th:text="${detail.description}"></textarea>
</div>
</div>
</td>
@ -285,11 +282,12 @@
</tbody>
</table>
<div class="layui-input-inline" th:if="${type == 'add'}">
<button type="button" onclick="sub()" class="layui-btn layui-btn-normal">提交</button>
<button type="button" onclick="sub('add')" class="layui-btn layui-btn-normal">提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
<div class="layui-input-inline" th:if="${type == 'detail'}">
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
<button type="button" onclick="sub('edit')" class="layui-btn layui-btn-normal">提交</button>
<button type="button" class="layui-btn layui-btn-primary" onclick="back()">返回</button>
</div>
</form>
@ -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></option>对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('<span class="layui-font-red">'+ (start ? timeNum : --timeNum) + '</span> 秒后自动关闭', 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='/';
}
</script>

@ -102,7 +102,7 @@
</div>
<div class="layui-input-inline">
<button type="button" onclick="loadTable()" class="layui-btn layui-btn-normal" style="width: 58px">查询</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
<button type="reset" class="layui-btn layui-btn-primary" onclick="resetLoad()">重置</button>
</div>
</div>
</form>
@ -125,7 +125,7 @@
<script type="text/html" id="templet-theads-tool">
<div class="layui-clear-space" style="padding-left: 20px">
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail"
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-on="detail" id="{{=d.celueid}}"
style="width: 46px;height: 26px;padding: 1px;background-color: #3cb754;color: white">
查看
</a>
@ -136,8 +136,6 @@
</div>
</script>
<script>
var pageNum=1;
var pageSize=10;
var total=0;
var laypage;
var name='';
@ -228,6 +226,9 @@ function loadTable(){
//layer.msg('点击取消的回调');
});
},
"detail":function (){
window.location='/celue/'+this.id;
}
})
form.on('switch(demo-templet-status)', function(obj){
var id = this.id;
@ -247,8 +248,12 @@ function loadTable(){
/*layer.tips(id + ' ' + name + ': '+ obj.elem.checked, obj.othis);*/
});
});
};
}
function resetLoad(){
$("#name").val('')
$("#status").val('')
loadTable()
}
function toAdd(){
window.location.href="/celue/add";
}

Loading…
Cancel
Save