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; } /**