diff --git a/src/main/java/com/example/zxweb/controller/CelueController.java b/src/main/java/com/example/zxweb/controller/CelueController.java index 05a40df..c750c47 100644 --- a/src/main/java/com/example/zxweb/controller/CelueController.java +++ b/src/main/java/com/example/zxweb/controller/CelueController.java @@ -1,9 +1,6 @@ package com.example.zxweb.controller; -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.example.zxweb.common.api.vo.Result; import com.example.zxweb.dto.ZxCelueDTO; import com.example.zxweb.entity.ZxCelue; @@ -12,12 +9,9 @@ import com.example.zxweb.vo.AddZxCeluePVO; import com.example.zxweb.vo.QueryCelueVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.util.List; /** * @Description 策略管理接口 @@ -59,8 +53,8 @@ public class CelueController { @ApiOperation(value = "编辑") @PutMapping - public Resultedit(@RequestBody ZxCelue zxCelue){ - zxCelueService.updateById(zxCelue); + public Resultedit(@RequestBody AddZxCeluePVO editZxCeluePVO){ + zxCelueService.saveZxCelue(editZxCeluePVO); return Result.OK("操作成功"); } 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 9ba39a6..b21fe23 100644 --- a/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java +++ b/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java @@ -13,7 +13,6 @@ 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; @@ -23,8 +22,6 @@ 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; @@ -32,10 +29,7 @@ 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; import java.util.List; @@ -61,6 +55,12 @@ public class ZxCelueServiceImpl extends ServiceImpl impl AssertUtils.hasSize(addZxCeluePVO.getDevidList(),"请选择[设备]"); try { BeanUtils.copyProperties(addZxCeluePVO,zxCelue); + String celueid = addZxCeluePVO.getCelueid(); + if(StringUtils.isNotBlank(celueid)){ + zxCelue.setCelueid(celueid); + }else{ + zxCelue.setCelueid(time+""); + } /*if (StringUtils.isBlank(zxCelue.getStartTime())) { zxCelue.setStartTime(DateFormatUtils.format(date,"yyyy-MM-dd")); } @@ -70,7 +70,6 @@ public class ZxCelueServiceImpl extends ServiceImpl impl 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(); @@ -103,16 +102,22 @@ public class ZxCelueServiceImpl extends ServiceImpl impl //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",StringUtils.isNotBlank(addZxCeluePVO.getStartTime())?addZxCeluePVO.getStartTime():null); - requestBodyJson.replace("%endDate",StringUtils.isNotBlank(addZxCeluePVO.getEndTime())?addZxCeluePVO.getEndTime():null); + requestBodyJson=requestBodyJson.replace("%serial",gateway_5lqh); + requestBodyJson=requestBodyJson.replace("%celueid", zxCelue.getCelueid()); + requestBodyJson=requestBodyJson.replace("%name",zxCelue.getName()); + requestBodyJson=requestBodyJson.replace("%cron",cron); + requestBodyJson=requestBodyJson.replace("%action",action.toString().replace("\"","\\\"")); + requestBodyJson=requestBodyJson.replace("%startDate",StringUtils.isNotBlank(addZxCeluePVO.getStartTime())?addZxCeluePVO.getStartTime():""); + requestBodyJson=requestBodyJson.replace("%endDate",StringUtils.isNotBlank(addZxCeluePVO.getEndTime())?addZxCeluePVO.getEndTime():""); JSONObject requestBody = JSONObject.parseObject(requestBodyJson); - IotUtils.celueSet(requestBody); - save(zxCelue); + if (active) { + IotUtils.celueSet(requestBody); + } + if (StringUtils.isNotBlank(celueid)) { + updateById(zxCelue); + }else{ + save(zxCelue); + } }catch (Exception e){ throw new BusinessException(e); } diff --git a/src/main/java/com/example/zxweb/vo/AddZxCeluePVO.java b/src/main/java/com/example/zxweb/vo/AddZxCeluePVO.java index f29c6bc..10ec8c0 100644 --- a/src/main/java/com/example/zxweb/vo/AddZxCeluePVO.java +++ b/src/main/java/com/example/zxweb/vo/AddZxCeluePVO.java @@ -16,6 +16,8 @@ import java.util.List; @Data @ApiModel(value = "新建策略信息对象") public class AddZxCeluePVO implements Serializable { + @ApiModelProperty(value = "策略id") + private String celueid; @ApiModelProperty(value = "选择设备id集合") private List devidList; @ApiModelProperty(value = "策略名称") diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 57bc1ae..a8c5569 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -84,7 +84,7 @@ mybatis-plus: table-underline: true configuration: # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 - #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 返回类型为Map,显示null对应的字段 call-setters-on-nulls: true diff --git a/src/main/resources/templates/add.html b/src/main/resources/templates/add.html index bcd8457..a6b48a3 100644 --- a/src/main/resources/templates/add.html +++ b/src/main/resources/templates/add.html @@ -539,14 +539,25 @@ startDate=day; endDate=day; }else if(timeType==='date'){ + if(checkNull(startDate)){ + layer.msg('请选择[策略执行开始日期]', {icon: 0}, function(){ + // layer.msg('提示框关闭后的回调'); + }); + return false; + } if(checkNull(startDate)&&checkNull(endDate)){ - layer.msg('请选择[选择日期]', {icon: 0}, function(){ + layer.msg('请选择[策略执行结束日期]', {icon: 0}, function(){ // layer.msg('提示框关闭后的回调'); }); return false; } } + if (checkNull(exeTime)) { + layer.msg('请选择[执行时段]', {icon: 0}, function(){}); + return false; + } + var index = layer.load(0, {shade: false}); var obj = { 'name':celueName,