From 89eea6a4a4787856690d4083796e4bd1030c6fc7 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Wed, 29 May 2024 19:47:06 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=8F=91=E9=80=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=BD=8E=E7=94=B5=E5=8E=8B=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/constant/IotConstants.java | 5 +++ .../service/impl/EtModelServiceImpl.java | 40 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java b/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java index d4541ed..e9ec82b 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java +++ b/electripper-common/src/main/java/com/ruoyi/common/constant/IotConstants.java @@ -56,6 +56,11 @@ public class IotConstants { */ public static final String COMMAND_SUB = "sub"; + /** + * 命令 发送低电压预警设置 + */ + public static final String COMMAND_BAT = "bat"; + /** * 命令 超出营运区(禁行区)断电,不进行轮动检测 */ diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java index 6be249a..212af84 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java @@ -5,15 +5,20 @@ import java.util.List; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.ruoyi.common.constant.IotConstants; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.onenet.Token; import com.ruoyi.system.domain.AsDevice; import com.ruoyi.system.mapper.AsDeviceMapper; import com.ruoyi.system.service.IAsDeviceService; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.EtModelMapper; import com.ruoyi.system.domain.EtModel; import com.ruoyi.system.service.IEtModelService; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; @@ -23,6 +28,7 @@ import javax.annotation.Resource; * @author 邱贞招 * @date 2024-05-13 */ +@Slf4j @Service public class EtModelServiceImpl implements IEtModelService { @@ -74,11 +80,26 @@ public class EtModelServiceImpl implements IEtModelService * @param etModel 车辆型号 * @return 结果 */ + @SneakyThrows @Override + @Transactional public int insertEtModel(EtModel etModel) { etModel.setCreateTime(DateUtils.getNowDate()); - return etModelMapper.insertEtModel(etModel); + int i = etModelMapper.insertEtModel(etModel); + // 发送设置低电压命令 + Integer lowBatteryReminder = etModel.getLowBatteryReminder(); + if(ObjectUtil.isNotNull(lowBatteryReminder) && lowBatteryReminder > 0){ + AsDevice device = new AsDevice(); + device.setModelId(etModel.getModelId()); + List asDevices = asDeviceService.selectAsDeviceList(device); + for(AsDevice asDevice: asDevices){ + String lowVoltageCommand = IotConstants.COMMAND_BAT + lowBatteryReminder * 10 + "@"; + log.info("发送低电压命令:" + lowVoltageCommand); + asDeviceService.sendCommand(asDevice.getMac(), Token.getToken(), lowVoltageCommand,"发送低电压播报"); + } + } + return i; } /** @@ -87,11 +108,26 @@ public class EtModelServiceImpl implements IEtModelService * @param etModel 车辆型号 * @return 结果 */ + @SneakyThrows @Override + @Transactional public int updateEtModel(EtModel etModel) { etModel.setUpdateTime(DateUtils.getNowDate()); - return etModelMapper.updateEtModel(etModel); + int i = etModelMapper.updateEtModel(etModel); + // 发送设置低电压命令 + Integer lowBatteryReminder = etModel.getLowBatteryReminder(); + if(ObjectUtil.isNotNull(lowBatteryReminder) && lowBatteryReminder > 0){ + AsDevice device = new AsDevice(); + device.setModelId(etModel.getModelId()); + List asDevices = asDeviceService.selectAsDeviceList(device); + for(AsDevice asDevice: asDevices){ + String lowVoltageCommand = IotConstants.COMMAND_BAT + lowBatteryReminder * 10 + "@"; + log.info("发送低电压命令:" + lowVoltageCommand); + asDeviceService.sendCommand(asDevice.getMac(), Token.getToken(), lowVoltageCommand,"发送低电压播报"); + } + } + return i; } /**