控制策略-创建
页面
main
周文涛 2 years ago
parent bc265ee302
commit 6efb4afa60

@ -1,5 +1,7 @@
package com.example.zxweb.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -11,9 +13,12 @@ import com.example.zxweb.service.IZxDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description
@ -28,10 +33,34 @@ public class DeviceController {
IZxDeviceService zxDeviceService;
@ApiOperation(value = "设备列表")
@GetMapping(value = "/list")
public Result<?> list(@RequestParam(value = "page",defaultValue = "1")Integer page,@RequestParam(value = "limit",defaultValue = "10")Integer limit){
@GetMapping(value = "/listAll")
public Result<?> listAll(){
LambdaQueryWrapper<ZxDevice> queryWrapper=new LambdaQueryWrapper<>();
return Result.ok(zxDeviceService.list(queryWrapper));
queryWrapper.isNotNull(ZxDevice::getSerial);
queryWrapper.isNotNull(ZxDevice::getTerminalName);
queryWrapper.in(ZxDevice::getType,"开关插座设备组","照明设备组");
List<ZxDevice> list = zxDeviceService.list(queryWrapper);
if (CollectionUtils.isEmpty(list)) {
return Result.OK(new ArrayList<>());
}
JSONArray allList=new JSONArray();
Map<String,List<JSONObject>> map=new LinkedHashMap<>();
for (ZxDevice zxDevice : list) {
String type = zxDevice.getType();
List<JSONObject> mapOrDefault = map.getOrDefault(type, new ArrayList<>());
JSONObject jo=new JSONObject();
jo.put("id",zxDevice.getSerial());
jo.put("text",zxDevice.getTerminalName());
mapOrDefault.add(jo);
map.put(type,mapOrDefault);
}
for (String key : map.keySet()) {
JSONObject jo=new JSONObject();
jo.put("text",key);
jo.put("children",map.get(key));
allList.add(jo);
}
return Result.OK(allList);
}

@ -14,9 +14,13 @@ import javax.servlet.http.HttpServletRequest;
public class ThymeleafController {
@RequestMapping("/")
public String getString(HttpServletRequest request){
String name = "全栈学习笔记";
public String index(HttpServletRequest request){
return "index.html";
}
@RequestMapping("/celue/add")
public String celueAdd(HttpServletRequest request){
return "add.html";
}
}

@ -38,6 +38,8 @@ public class ZxCelue implements Serializable {
private String xunhuanzhouqi;
@ApiModelProperty(value = "状态(1启动中/0关闭中)")
private String status;
@ApiModelProperty(value = "事件类型")
private String type;
@ApiModelProperty(value = "备注")
private String description;
@ApiModelProperty(value = "定时触发条件")

@ -30,6 +30,8 @@ public class ZxDevice implements Serializable {
private String serial;
@ApiModelProperty(value = "设备名称")
private String terminalName;
@ApiModelProperty(value = "设备类型")
@ApiModelProperty(value = "模型编码")
private String modelCode;
@ApiModelProperty(value = "设备类型")
private String type;
}

@ -0,0 +1,36 @@
package com.example.zxweb.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/9/13 13:41
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="zx_device_method对象", description="zx_device_method对象")
@TableName(value = "zx_device_method")
public class ZxDeviceMethod implements Serializable {
@ApiModelProperty(value = "模型编码")
private String modelCode;
@ApiModelProperty(value = "下行方法")
private String method;
@ApiModelProperty(value = "下方方法名称")
private String methodName;
@ApiModelProperty(value = "参数")
private String parameter;
}

@ -0,0 +1,14 @@
package com.example.zxweb.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.zxweb.entity.ZxDeviceMethod;
import org.apache.ibatis.annotations.Mapper;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/9/15 09:05
*/
@Mapper
public interface ZxDeviceMethodMapper extends BaseMapper<ZxDeviceMethod> {
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.zxweb.mapper.ZxDeviceMethodMapper">
</mapper>

@ -2,6 +2,9 @@ package com.example.zxweb.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.zxweb.entity.ZxDevice;
import com.example.zxweb.entity.ZxDeviceMethod;
import java.util.List;
/**
* @Description
@ -9,4 +12,10 @@ import com.example.zxweb.entity.ZxDevice;
* @Date 2023/9/14 9:14
*/
public interface IZxDeviceService extends IService<ZxDevice> {
/**
*
* @param modelCode
* @return
*/
public List<ZxDeviceMethod> getMethodByDeviceModelCode(String modelCode);
}

@ -1,27 +1,40 @@
package com.example.zxweb.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zxweb.common.constant.DevConstant;
import com.example.zxweb.dto.ZxCelueDTO;
import com.example.zxweb.entity.ZxCelue;
import com.example.zxweb.entity.ZxDevice;
import com.example.zxweb.entity.ZxDeviceMethod;
import com.example.zxweb.exception.BusinessException;
import com.example.zxweb.mapper.ZxCelueMapper;
import com.example.zxweb.mapper.ZxDeviceMethodMapper;
import com.example.zxweb.service.IZxCelueService;
import com.example.zxweb.service.IZxDeviceService;
import com.example.zxweb.utils.AssertUtils;
import com.example.zxweb.utils.CronLowUtil;
import com.example.zxweb.utils.IotUtils;
import com.example.zxweb.vo.AddZxCeluePVO;
import com.example.zxweb.vo.QueryCelueVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@ -35,9 +48,72 @@ import java.util.stream.Collectors;
public class ZxCelueServiceImpl extends ServiceImpl<ZxCelueMapper, ZxCelue> implements IZxCelueService {
@Value("${iot.active}")
private boolean active;
@Resource
private IZxDeviceService zxDeviceService;
@Override
public boolean saveZxCelue(AddZxCeluePVO addZxCeluePVO) {
return false;
Date date = new Date();
long time = date.getTime();
ZxCelue zxCelue=new ZxCelue();
AssertUtils.hasSize(addZxCeluePVO.getDevidList(),"请选择[设备]");
try {
BeanUtils.copyProperties(addZxCeluePVO,zxCelue);
if (StringUtils.isBlank(zxCelue.getStartTime())) {
zxCelue.setStartTime(DateFormatUtils.format(date,"yyyy-MM-dd"));
}
if (StringUtils.isBlank(zxCelue.getEndTime())) {
zxCelue.setEndTime("2099-12-31");
}
if (!CollectionUtils.isEmpty(addZxCeluePVO.getDevidList())) {
zxCelue.setDevid(String.join(",", addZxCeluePVO.getDevidList()));
}
zxCelue.setCelueid(time+"");
String cron = CronLowUtil.getCron(addZxCeluePVO.getTimeType(), addZxCeluePVO.getExeTime(), addZxCeluePVO.getWeeklyDay(), addZxCeluePVO.getDay(), addZxCeluePVO.getStartTime(), addZxCeluePVO.getEndTime());
zxCelue.setTriggereTime(cron);
String type = addZxCeluePVO.getType();
String gateway_5lqh = DevConstant.gateway.gateway_5lqh;
//获取设备信息
LambdaQueryWrapper<ZxDevice> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(ZxDevice::getSerial,addZxCeluePVO.getDevidList());
List<ZxDevice> deviceList = zxDeviceService.list(queryWrapper);
StringBuilder action=new StringBuilder();
//拼接触发动作
for (ZxDevice zxDevice : deviceList) {
//设备号
String serial = zxDevice.getSerial();
//设备型号
String modelCode = zxDevice.getModelCode();
List<ZxDeviceMethod> methodList = zxDeviceService.getMethodByDeviceModelCode(zxDevice.getModelCode());
AssertUtils.hasSize(methodList,String.format("设备-[%s] 未找到可执行方法",zxDevice.getTerminalName()));
ZxDeviceMethod zxDeviceMethod = methodList.get(0);
//可执行方法
String method = zxDeviceMethod.getMethod();
//参数
String[] parameters = zxDeviceMethod.getParameter().split(",");
for (String parameter: parameters) {
if (action.length()>0) {
action.append("&&");
}
//设备号.设备型号.下行方法.参数.操作值
action.append(String.format("%s.%s.%s.%s=\"%s\"",serial,modelCode,method,parameter,type));
}
//String s = "s10001.switch1.controlSwitch1.ctrl_ch0_status=\"1\"&&s10002.switch1.controlSwitch1.ctrl_ch0_status=\"1\"";
}
String requestBodyJson="{\"serial\":\"%serial\",\"productId\":\"\",\"methodName\":\"celueSet\",\"inputData\":{\"devid\":\"%serial\",\"celueid\":\"%celueid\",\"name\":\"%name\",\"triggereTime\":\"%cron\",\"action\":\"%action\",\"startTime\":\"%startDate\",\"endTime\":\"%endDate\"}}";
requestBodyJson.replace("%serial",gateway_5lqh);
requestBodyJson.replace("%celueid", zxCelue.getCelueid());
requestBodyJson.replace("%name",zxCelue.getName());
requestBodyJson.replace("%cron",cron);
requestBodyJson.replace("%action",action);
requestBodyJson.replace("%startDate",addZxCeluePVO.getStartTime());
requestBodyJson.replace("%endDate",addZxCeluePVO.getEndTime());
JSONObject requestBody = JSONObject.parseObject(requestBodyJson);
IotUtils.celueSet(requestBody);
save(zxCelue);
}catch (Exception e){
throw new BusinessException(e);
}
return true;
}
@Override
@ -109,6 +185,9 @@ public class ZxCelueServiceImpl extends ServiceImpl<ZxCelueMapper, ZxCelue> impl
return zxCelueDTO;
}
public static void ss(){
}
public static void main(String[] args) {
String timeType="day";
String exeTime="08:30";

@ -1,12 +1,18 @@
package com.example.zxweb.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zxweb.entity.ZxDevice;
import com.example.zxweb.entity.ZxDeviceMethod;
import com.example.zxweb.mapper.ZxDeviceMapper;
import com.example.zxweb.mapper.ZxDeviceMethodMapper;
import com.example.zxweb.service.IZxDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @Description
* @Author ZhouWenTao
@ -15,4 +21,10 @@ import org.springframework.stereotype.Service;
@Service
@Slf4j
public class ZxDeviceServiceImpl extends ServiceImpl<ZxDeviceMapper, ZxDevice> implements IZxDeviceService {
@Resource
private ZxDeviceMethodMapper zxDeviceMethodMapper;
@Override
public List<ZxDeviceMethod> getMethodByDeviceModelCode(String modelCode) {
return zxDeviceMethodMapper.selectList(new LambdaQueryWrapper<ZxDeviceMethod>().eq(ZxDeviceMethod::getModelCode,modelCode).isNotNull(ZxDeviceMethod::getParameter));
}
}

@ -49,6 +49,32 @@ public class IotUtils {
return list;
}
/**
* {"serial":"0cefafd605f7","productId":"", "methodName":"celueSet","inputData":{"devid":"0cefafd605f7","celueid":"100000000003","name":"策略3","triggereTime":"20 18 * * 1,4,6","action":"e826ecfeff81f68c.light.controlLight.ctrl_ch0_status=\"0\"","startTime":"2023-09-12 10:00:00","endTime":"2023-09-30 11:30:00" }}
* @param requestBody
* @return
*/
public static boolean celueSet(JSONObject requestBody){
JSONObject responseBody = postApi(IotApiEnum.getPathByText("向设备发送方法"), requestBody);
try {
if (responseBody!=null) {
JSONObject data = responseBody.getJSONObject("data");
if (data!=null) {
JSONObject outputData = data.getJSONObject("outputData");
if (outputData!=null) {
Integer code = outputData.getInteger("code");
if (code==1) {
return true;
}
}
}
}
}catch (Exception e){
throw new BusinessException(e);
}
return false;
}
/**
*
* @param celueId id

@ -3,6 +3,7 @@ package com.example.zxweb.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@ -12,6 +13,7 @@ import java.util.List;
* @Author ZhouWenTao
* @Date 2023/9/14 9:44
*/
@Data
@ApiModel(value = "新建策略信息对象")
public class AddZxCeluePVO implements Serializable {
@ApiModelProperty(value = "选择设备id集合")
@ -27,12 +29,14 @@ public class AddZxCeluePVO implements Serializable {
@ApiModelProperty(value = "1,2,3周一,周二,周三")
private String weeklyDay;//1,2,3周一,周二,周三
@ApiModelProperty(value = "每月的第几天,1,31 每月1日31日")
private String day;//每月的第几天,1,31 每月1日31日
private String day;// 每月的第几天,1,31 每月1日31日
/*@ApiModelProperty(value = "每月的第几天,1,31 每月1日31日")
private String day;// 每月的第几天,1,31 每月1日31日*/
@ApiModelProperty(value = "范围型,开始日期 2023-09-10")
private String startDate;//范围型,开始日期 2023-09-10
private String startTime;//范围型,开始日期 2023-09-10
@ApiModelProperty(value = "范围型,截止日期 2023-09-30")
private String endDate;//范围型,截止日期 2023-09-30
private String endTime;//范围型,截止日期 2023-09-30
@ApiModelProperty(value = "备注")
private String description;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,627 @@
.select2-container {
box-sizing: border-box;
display: inline-block;
margin: 0;
position: relative;
vertical-align: middle
}
.select2-container .select2-selection--single {
box-sizing: border-box;
cursor: pointer;
display: block;
height: 28px;
user-select: none;
-webkit-user-select: none
}
.select2-container .select2-selection--single .select2-selection__rendered {
display: block;
padding-left: 8px;
padding-right: 20px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap
}
.select2-container .select2-selection--single .select2-selection__clear {
position: relative
}
.select2-container[dir="rtl"] .select2-selection--single .select2-selection__rendered {
padding-right: 8px;
padding-left: 20px
}
.select2-container .select2-selection--multiple {
box-sizing: border-box;
cursor: pointer;
display: block;
min-height: 32px;
user-select: none;
-webkit-user-select: none
}
.select2-container .select2-selection--multiple .select2-selection__rendered {
display: inline-block;
overflow: hidden;
padding-left: 8px;
text-overflow: ellipsis;
white-space: nowrap
}
.select2-container .select2-search--inline {
float: left
}
.select2-container .select2-search--inline .select2-search__field {
box-sizing: border-box;
border: none;
font-size: 100%;
margin-top: 5px;
padding: 0
}
.select2-container .select2-search--inline .select2-search__field::-webkit-search-cancel-button {
-webkit-appearance: none
}
.select2-dropdown {
background-color: white;
border: 1px solid #aaa;
border-radius: 4px;
box-sizing: border-box;
display: block;
position: absolute;
left: -100000px;
width: 100%;
z-index: 1051
}
.select2-results {
display: block
}
.select2-results__options {
list-style: none;
margin: 0;
padding: 0
}
.select2-results__option {
padding: 6px;
user-select: none;
-webkit-user-select: none
}
.select2-results__option[aria-selected] {
cursor: pointer
}
.select2-container--open .select2-dropdown {
left: 0
}
.select2-container--open .select2-dropdown--above {
border-bottom: none;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0
}
.select2-container--open .select2-dropdown--below {
border-top: none;
border-top-left-radius: 0;
border-top-right-radius: 0
}
.select2-search--dropdown {
display: block;
padding: 4px
}
.select2-search--dropdown .select2-search__field {
padding: 4px;
width: 100%;
box-sizing: border-box
}
.select2-search--dropdown .select2-search__field::-webkit-search-cancel-button {
-webkit-appearance: none
}
.select2-search--dropdown.select2-search--hide {
display: none
}
.select2-close-mask {
border: 0;
margin: 0;
padding: 0;
display: block;
position: fixed;
left: 0;
top: 0;
min-height: 100%;
min-width: 100%;
height: auto;
width: auto;
opacity: 0;
z-index: 99;
background-color: #fff;
filter: alpha(opacity=0)
}
.select2-hidden-accessible {
border: 0 !important;
clip: rect(0 0 0 0) !important;
-webkit-clip-path: inset(50%) !important;
clip-path: inset(50%) !important;
height: 1px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
width: 1px !important;
white-space: nowrap !important
}
.select2-container--default .select2-selection--single {
background-color: #fff;
border: 1px solid #aaa;
border-radius: 4px
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
color: #444;
line-height: 28px
}
.select2-container--default .select2-selection--single .select2-selection__clear {
cursor: pointer;
float: right;
font-weight: bold
}
.select2-container--default .select2-selection--single .select2-selection__placeholder {
color: #999
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 26px;
position: absolute;
top: 1px;
right: 1px;
width: 20px
}
.select2-container--default .select2-selection--single .select2-selection__arrow b {
border-color: #888 transparent transparent transparent;
border-style: solid;
border-width: 5px 4px 0 4px;
height: 0;
left: 50%;
margin-left: -4px;
margin-top: -2px;
position: absolute;
top: 50%;
width: 0
}
.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__clear {
float: left
}
.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__arrow {
left: 1px;
right: auto
}
.select2-container--default.select2-container--disabled .select2-selection--single {
background-color: #eee;
cursor: default
}
.select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__clear {
display: none
}
.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
border-color: transparent transparent #888 transparent;
border-width: 0 4px 5px 4px
}
.select2-container--default .select2-selection--multiple {
background-color: white;
border: 1px solid #aaa;
border-radius: 4px;
cursor: text
}
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
box-sizing: border-box;
list-style: none;
margin: 0;
padding: 0 5px;
width: 100%
}
.select2-container--default .select2-selection--multiple .select2-selection__rendered li {
list-style: none
}
.select2-container--default .select2-selection--multiple .select2-selection__clear {
cursor: pointer;
float: right;
font-weight: bold;
margin-top: 5px;
margin-right: 10px
}
.select2-container--default .select2-selection--multiple .select2-selection__choice {
background-color: #e4e4e4;
border: 1px solid #aaa;
border-radius: 4px;
cursor: default;
float: left;
margin-right: 5px;
margin-top: 5px;
padding: 0 5px
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
color: #999;
cursor: pointer;
display: inline-block;
font-weight: bold;
margin-right: 2px
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
color: #333
}
.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice,.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-search--inline {
float: right
}
.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
margin-left: 5px;
margin-right: auto
}
.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
margin-left: 2px;
margin-right: auto
}
.select2-container--default.select2-container--focus .select2-selection--multiple {
border: solid black 1px;
outline: 0
}
.select2-container--default.select2-container--disabled .select2-selection--multiple {
background-color: #eee;
cursor: default
}
.select2-container--default.select2-container--disabled .select2-selection__choice__remove {
display: none
}
.select2-container--default.select2-container--open.select2-container--above .select2-selection--single,.select2-container--default.select2-container--open.select2-container--above .select2-selection--multiple {
border-top-left-radius: 0;
border-top-right-radius: 0
}
.select2-container--default.select2-container--open.select2-container--below .select2-selection--single,.select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0
}
.select2-container--default .select2-search--dropdown .select2-search__field {
border: 1px solid #aaa
}
.select2-container--default .select2-search--inline .select2-search__field {
background: transparent;
border: none;
outline: 0;
box-shadow: none;
-webkit-appearance: textfield
}
.select2-container--default .select2-results>.select2-results__options {
max-height: 200px;
overflow-y: auto
}
.select2-container--default .select2-results__option[role=group] {
padding: 0
}
.select2-container--default .select2-results__option[aria-disabled=true] {
color: #999
}
.select2-container--default .select2-results__option[aria-selected=true] {
background-color: #ddd
}
.select2-container--default .select2-results__option .select2-results__option {
padding-left: 1em
}
.select2-container--default .select2-results__option .select2-results__option .select2-results__group {
padding-left: 0
}
.select2-container--default .select2-results__option .select2-results__option .select2-results__option {
margin-left: -1em;
padding-left: 2em
}
.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
margin-left: -2em;
padding-left: 3em
}
.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
margin-left: -3em;
padding-left: 4em
}
.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
margin-left: -4em;
padding-left: 5em
}
.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
margin-left: -5em;
padding-left: 6em
}
.select2-container--default .select2-results__option--highlighted[aria-selected] {
background-color: #5897fb;
color: white
}
.select2-container--default .select2-results__group {
cursor: default;
display: block;
padding: 6px
}
.select2-container--classic .select2-selection--single {
background-color: #f7f7f7;
border: 1px solid #aaa;
border-radius: 4px;
outline: 0;
background-image: -webkit-linear-gradient(top, #fff 50%, #eee 100%);
background-image: -o-linear-gradient(top, #fff 50%, #eee 100%);
background-image: linear-gradient(to bottom, #fff 50%, #eee 100%);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0)
}
.select2-container--classic .select2-selection--single:focus {
border: 1px solid #5897fb
}
.select2-container--classic .select2-selection--single .select2-selection__rendered {
color: #444;
line-height: 28px
}
.select2-container--classic .select2-selection--single .select2-selection__clear {
cursor: pointer;
float: right;
font-weight: bold;
margin-right: 10px
}
.select2-container--classic .select2-selection--single .select2-selection__placeholder {
color: #999
}
.select2-container--classic .select2-selection--single .select2-selection__arrow {
background-color: #ddd;
border: none;
border-left: 1px solid #aaa;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
height: 26px;
position: absolute;
top: 1px;
right: 1px;
width: 20px;
background-image: -webkit-linear-gradient(top, #eee 50%, #ccc 100%);
background-image: -o-linear-gradient(top, #eee 50%, #ccc 100%);
background-image: linear-gradient(to bottom, #eee 50%, #ccc 100%);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFCCCCCC', GradientType=0)
}
.select2-container--classic .select2-selection--single .select2-selection__arrow b {
border-color: #888 transparent transparent transparent;
border-style: solid;
border-width: 5px 4px 0 4px;
height: 0;
left: 50%;
margin-left: -4px;
margin-top: -2px;
position: absolute;
top: 50%;
width: 0
}
.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__clear {
float: left
}
.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__arrow {
border: none;
border-right: 1px solid #aaa;
border-radius: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
left: 1px;
right: auto
}
.select2-container--classic.select2-container--open .select2-selection--single {
border: 1px solid #5897fb
}
.select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow {
background: transparent;
border: none
}
.select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow b {
border-color: transparent transparent #888 transparent;
border-width: 0 4px 5px 4px
}
.select2-container--classic.select2-container--open.select2-container--above .select2-selection--single {
border-top: none;
border-top-left-radius: 0;
border-top-right-radius: 0;
background-image: -webkit-linear-gradient(top, #fff 0%, #eee 50%);
background-image: -o-linear-gradient(top, #fff 0%, #eee 50%);
background-image: linear-gradient(to bottom, #fff 0%, #eee 50%);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0)
}
.select2-container--classic.select2-container--open.select2-container--below .select2-selection--single {
border-bottom: none;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
background-image: -webkit-linear-gradient(top, #eee 50%, #fff 100%);
background-image: -o-linear-gradient(top, #eee 50%, #fff 100%);
background-image: linear-gradient(to bottom, #eee 50%, #fff 100%);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFFFFFFF', GradientType=0)
}
.select2-container--classic .select2-selection--multiple {
background-color: white;
border: 1px solid #aaa;
border-radius: 4px;
cursor: text;
outline: 0
}
.select2-container--classic .select2-selection--multiple:focus {
border: 1px solid #5897fb
}
.select2-container--classic .select2-selection--multiple .select2-selection__rendered {
list-style: none;
margin: 0;
padding: 0 5px
}
.select2-container--classic .select2-selection--multiple .select2-selection__clear {
display: none
}
.select2-container--classic .select2-selection--multiple .select2-selection__choice {
background-color: #e4e4e4;
border: 1px solid #aaa;
border-radius: 4px;
cursor: default;
float: left;
margin-right: 5px;
margin-top: 5px;
padding: 0 5px
}
.select2-container--classic .select2-selection--multiple .select2-selection__choice__remove {
color: #888;
cursor: pointer;
display: inline-block;
font-weight: bold;
margin-right: 2px
}
.select2-container--classic .select2-selection--multiple .select2-selection__choice__remove:hover {
color: #555
}
.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
float: right;
margin-left: 5px;
margin-right: auto
}
.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
margin-left: 2px;
margin-right: auto
}
.select2-container--classic.select2-container--open .select2-selection--multiple {
border: 1px solid #5897fb
}
.select2-container--classic.select2-container--open.select2-container--above .select2-selection--multiple {
border-top: none;
border-top-left-radius: 0;
border-top-right-radius: 0
}
.select2-container--classic.select2-container--open.select2-container--below .select2-selection--multiple {
border-bottom: none;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0
}
.select2-container--classic .select2-search--dropdown .select2-search__field {
border: 1px solid #aaa;
outline: 0
}
.select2-container--classic .select2-search--inline .select2-search__field {
outline: 0;
box-shadow: none
}
.select2-container--classic .select2-dropdown {
background-color: #fff;
border: 1px solid transparent
}
.select2-container--classic .select2-dropdown--above {
border-bottom: none
}
.select2-container--classic .select2-dropdown--below {
border-top: none
}
.select2-container--classic .select2-results>.select2-results__options {
max-height: 200px;
overflow-y: auto
}
.select2-container--classic .select2-results__option[role=group] {
padding: 0
}
.select2-container--classic .select2-results__option[aria-disabled=true] {
color: grey
}
.select2-container--classic .select2-results__option--highlighted[aria-selected] {
background-color: #3875d7;
color: #fff
}
.select2-container--classic .select2-results__group {
cursor: default;
display: block;
padding: 6px
}
.select2-container--classic.select2-container--open .select2-dropdown {
border-color: #5897fb
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,563 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org/">
<head>
<meta charset="UTF-8">
<title>新增控制策略</title>
<!-- 引入 layui.css -->
<link href="../static/layui-v2.8.11/css/layui.css" rel="stylesheet">
<link href="../static/formSelects-v4/formSelects-v4.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>
<!-- 加载 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>
<style>
body {
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
.body {
padding: 23.8px;
}
.left-title {
font-size: 22px;
margin-bottom: 15px;
margin-top: 15px;
}
.z-body {
}
.z-body .layui-form-label {
font-size: 14px;
}
.layui-input-inline{
display: flex;
justify-content: center;
align-items: center;
}
.z-body .layui-input-inline .layui-btn {
padding: 0;
height: 36px;
width: 80px;
line-height: 0px;
}
.z-search .layui-form-item {
margin: 10px 0px;
display: flex;
justify-content: center;
align-items: center;
}
table th {
background-color: #fafafa;
color: #2c2a29;
}
.layui-form-onswitch {
border-color: #1890ff;
background-color: #1890ff;
}
.layui-table-body .layui-table-cell {
height: 56px;
line-height: 41px;
}
.layui-table-column {
display: flex;
justify-content: flex-end;
}
/*单选按钮颜色*/
.layui-form-radio:hover>*, .layui-form-radioed, .layui-form-radioed>i{
color: #1890ff;
}
.layui-form-radio{
padding-right: 35px;
}
.layui-input-split{
/*border-color: #7f6666 !important;*/
/*border-width:1px;*/
}
/*设置奇数行颜色*/
table tr:nth-child(odd)
{
/*background: #f5f5f5;*/
}
/*设置偶数行颜色*/
table tr:nth-child(even)
{
/*background: #f5f5f5;*/
}
.layui-col-md7 {
width: 50.6%;
}
.layui-laydate-linkage .layui-laydate-content td.laydate-selected>div {
background-color: #83bdf5;
}
.select2{
width: 50.6% !important;
}
.select2-selection__choice__remove{
float: right !important;
}
.select2-container--default .select2-selection--multiple{
border: 1px solid #eee !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 {
border-color: #c1c1c1;
}*/
</style>
</head>
<body>
<div class="body">
<div class="left-title layui-row">
<div class="layui-col-md6 layui-col-xs6 layui-col-sm6 layui-col-lg6 layui-col-xl6">
<p>新增控制策略</p>
</div>
<div class="layui-col-md6 layui-col-xs6 layui-col-sm6 layui-col-lg6 layui-col-xl6">
<!--<button type="button" class="layui-btn" style="font-size: 16px;float: right;background-color: #41a69a">返回</button>-->
</div>
</div>
<div class="z-body">
<div class="layui-card layui-panel">
<div class="layui-card-body z-search">
<form>
<table class="layui-table">
<colgroup>
<col width="150">
<col>
</colgroup>
<tbody>
<tr>
<td>策略名称:</td>
<td>
<div class="layui-col-md7">
<div class="layui-form">
<input type="text" name="name" id="celueName" placeholder="请填写策略名称···" class="layui-input">
</div>
</div>
</td>
</tr>
<tr>
<td>选择设备:</td>
<td>
<select id="id_select2_demo1" class="layui-col-md7" multiple="multiple">
<!--  <optgroup label="Group 1" class="group-1">
    <option value="1-1">Option 1.1</option>
    <option value="1-2">Option 1.2</option>
    <option value="1-3">Option 1.3</option>
  </optgroup>
  <optgroup label="Group 2" class="group-2">
    <option value="2-1">Option 2.1</option>
    <option value="2-2">Option 2.2</option>
    <option value="2-3">Option 2.3</option>
  </optgroup>-->
</select>
</td>
</tr>
<tr>
<td>操作类型</td>
<td>
<div class="layui-form layui-row layui-col-space16">
<div class="layui-col-md3">
<select id="type">
<option value="">请选择</option>
<option value="开灯">开灯</option>
<option value="关灯">关灯</option>
</select>
</div>
</div>
</td>
</tr>
<tr>
<td>执行周期:</td>
<td>
<div class="layui-form">
<input type="radio" name="timeType" value="everyDay" lay-filter="demo-radio-filter" title="每天" checked>
<input type="radio" name="timeType" value="weekly" lay-filter="demo-radio-filter" title="每周">
<input type="radio" name="timeType" value="day" lay-filter="demo-radio-filter" title="单日">
<input type="radio" name="timeType" value="date" lay-filter="demo-radio-filter" title="日期段">
<!--<input type="radio" name="AAA" value="3" title="禁用" disabled>-->
</div>
</td>
</tr>
<tr id="weeklyTr">
<!---->
<td>选择日期:</td>
<td>
<div class="layui-col-md6" id="weeklyDiv">
<div class="layui-form">
<input type="checkbox" name="weeklyDay" title="星期一" value="1">
<input type="checkbox" name="weeklyDay" title="星期二" value="2">
<input type="checkbox" name="weeklyDay" title="星期三" value="3">
<input type="checkbox" name="weeklyDay" title="星期四" value="4">
<input type="checkbox" name="weeklyDay" title="星期五" value="5">
<input type="checkbox" name="weeklyDay" title="星期六" value="6">
<input type="checkbox" name="weeklyDay" title="星期日" value="7">
<!--<input type="checkbox" name="weeklyDay" lay-text="选中" checked>
<input type="checkbox" name="weeklyDay" title="禁用" disabled>-->
</div>
</div>
</td>
</tr>
<tr id="dayTr">
<!--单日-->
<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="选择策略执行时间">
<div class="layui-input-split layui-input-suffix" style="background-color: #f5f5f5">
<i class="layui-icon layui-icon-time"></i>
</div>
</div>
</div>
</td>
</tr>
<tr id="dateTr">
<!--范围-->
<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="选择策略执行开始日期">
<div class="layui-input-split layui-input-suffix" style="background-color: #f5f5f5">
<i class="layui-icon layui-icon-date"></i>
</div>
</div>
</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="选择策略执行结束日期">
<div class="layui-input-split layui-input-suffix" style="background-color: #f5f5f5">
<i class="layui-icon layui-icon-date"></i>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>执行时段:</td>
<td>
<div class="layui-col-md3">
<div class="layui-input-wrap">
<input type="text" class="layui-input" id="ID-laydate-type-time" placeholder="选择策略开始时间">
<div class="layui-input-split layui-input-suffix" style="background-color: #f5f5f5">
<i class="layui-icon layui-icon-time"></i>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>备注信息:</td>
<td>
<div class="layui-col-md7">
<div class="layui-form">
<textarea name="detail" id="detail" placeholder="请填写备注文字···" class="layui-textarea"></textarea>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<div class="layui-input-inline">
<button type="button" onclick="sub()" class="layui-btn layui-btn-normal">提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
var laypage;
var name='';
var status='';
getDeviceList()
/*select2 回显*/
var str='1,2,3';
var arr=str.split(',');
//$('#id_select2_demo1').val(arr).trigger('change')
loadTable();
var form;
function loadTable(){
layui.use('table', function () {
var table = layui.table;
var $=layui.$;
var util = layui.util;
var laydate = layui.laydate;
form = layui.form;
// 时间选择器
laydate.render({
elem: '#ID-laydate-demo'
});
laydate.render({
elem: '#ID-laydate-type-time',
type: 'time'
});
// 日期范围 - 左右面板联动选择模式
laydate.render({
elem: '#ID-laydate-rangeLinked',
range: ['#ID-laydate-start-date-1', '#ID-laydate-end-date-1'],
rangeLinked: true // 开启日期范围选择时的区间联动标注模式 --- 2.8+ 新增
});
$("#weeklyTr").hide();
$("#dayTr").hide();
$("#dateTr").hide();
/*$('#dayTr').hide();
$('#dayTr2').show();*/
// 事件
// radio 事件
form.on('radio(demo-radio-filter)', function(data){
var elem = data.elem; // 获得 radio 原始 DOM 对象
var checked = elem.checked; // 获得 radio 选中状态
var value = elem.value; // 获得 radio 值
var othis = data.othis; // 获得 radio 元素被替换后的 jQuery 对象
var i=0;
console.log(value)
if(value=='weekly'){
$("#weeklyTr").show();
$("#dayTr").hide();
$("#dateTr").hide();
}else if (value == 'day') {
$("#weeklyTr").hide();
$("#dayTr").show();
$("#dateTr").hide();
}else if(value==='date'){
$("#weeklyTr").hide();
$("#dayTr").hide();
$("#dateTr").show();
}else{
$("#weeklyTr").hide();
$("#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", '');
}
}
})
}*/
});
});
};
function sub(){
//策略名称
let celueName = $("#celueName").val();
//选择设备
let devidList = $("#id_select2_demo1").val();
let type = $("#type").val();
//执行周期
let timeType = null;
var radio = document.getElementsByName("timeType");
for (i=0; i<radio.length; i++) {
if (radio[i].checked) {
timeType = radio[i].value;
}
}
//执行时段
let exeTime = $("#ID-laydate-type-time").val();
//每周-选择日期
//let weeklyDay=$("#weeklyDay").val();
let weeklyDay = document.getElementsByName("weeklyDay");
var weeklyDayList = [];
if (weeklyDay != null) {
for(k in weeklyDay){
if(weeklyDay[k].checked)
weeklyDayList.push(weeklyDay[k].value);
}
}
//单日-选择日期
let day=$("#ID-laydate-demo").val();
//日期段-选择日期
let startDate = $("#ID-laydate-start-date-1").val();
let endDate = $("#ID-laydate-end-date-1").val();
//描述
let description = $("#detail").val();
console.log('策略名称:'+celueName)
console.log('选择设备:'+devidList)
console.log('执行周期:'+timeType)
console.log('执行时段:'+exeTime)
console.log('每周-选择日期:'+weeklyDayList)
console.log('单日-选择日期:'+day)
console.log('日期段-选择日期:'+startDate+"-"+endDate)
if(checkNull(celueName)){
layer.msg('请输入[策略名称]', {icon: 0}, function(){
// layer.msg('提示框关闭后的回调');
});
return false;
}
if(checkArray(devidList)){
layer.msg('请选择[设备]', {icon: 0}, function(){
// layer.msg('提示框关闭后的回调');
});
return false;
}
if(timeType=='weekly'){
if (checkArray(weeklyDayList)) {
layer.msg('请选择[选择日期]', {icon: 0}, function(){
// layer.msg('提示框关闭后的回调');
});
return false;
}
}else if (timeType == 'day') {
if (checkNull(day)) {
layer.msg('请选择[选择日期]', {icon: 0}, function(){
// layer.msg('提示框关闭后的回调');
});
return false;
}
startDate=day;
endDate=day;
}else if(timeType==='date'){
if(checkNull(startDate)&&checkNull(endDate)){
layer.msg('请选择[选择日期]', {icon: 0}, function(){
// layer.msg('提示框关闭后的回调');
});
return false;
}
}
var index = layer.load(0, {shade: false});
//请求保存
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
});
$.ajax({
type: "POST",
url: "/celue",
data: obj,
contentType: 'application/json;charset=utf-8',
success: function(res){
console.log(res)
layer.close(index);
if (res.success) {
layer.msg(res.message, {icon: 0});
}else{
layer.msg(res.message, {icon: 0});
}
},error:function (res){
layer.close(index);
layer.msg(res.message, {icon: 0});
}
});
setTimeout(function(){
layer.close(index); // 关闭 loading
}, 5000);
}
function checkNull(o){
if (o == null || o == undefined || o == '') {
return true;
}
return false;
}
function checkArray(a){
if (a == null || a == undefined || a.length == 0) {
return true;
}
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();
var data=[
{
"text": "照明设备组",
"children": [
{
"id": "1",
"text": "1F左侧走廊照明灯组"
},
{
"id": 2,
"text": "1F右侧走廊照明灯组"
},
{
"id": 3,
"text": "2F左侧走廊照明灯组"
},
{
"id": 4,
"text": "2F右侧走廊照明灯组"
}
],
}
];
$("#id_select2_demo1").select2({
data:res.result
});
}else{
}
},error:function (res){
/*layer.msg('删除失败,'+res.message, {icon: 1});*/
}
});
}
</script>
</body>
</html>

@ -2,7 +2,7 @@
<html lang="en" xmlns:th="https://www.thymeleaf.org/">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>控制策略</title>
<!-- 引入 layui.css -->
<link href="../static/layui-v2.8.11/css/layui.css" rel="stylesheet">
<!-- 引入 layui.js -->
@ -79,7 +79,7 @@
<p>控制策略</p>
</div>
<div class="layui-col-md6 layui-col-xs6 layui-col-sm6 layui-col-lg6 layui-col-xl6">
<button type="button" class="layui-btn" style="font-size: 16px;float: right;background-color: #41a69a">+新增</button>
<button type="button" class="layui-btn" onclick="toAdd()" style="font-size: 16px;float: right;background-color: #41a69a">+新增</button>
</div>
</div>
<div class="z-body">
@ -247,6 +247,10 @@ function loadTable(){
});
};
function toAdd(){
window.location.href="/celue/add";
}
</script>

Loading…
Cancel
Save