From 611f3d05423954d50ec8cedd345126ffe9159dd3 Mon Sep 17 00:00:00 2001 From: tianyongbao Date: Sun, 29 Mar 2026 22:44:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=B0=E5=A2=9E=E5=A4=AA=E9=98=B3?= =?UTF-8?q?=E8=83=BD=E7=BD=91=E6=8E=A7=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E7=BD=AE=E5=A4=AA=E9=98=B3=E8=83=BD=E7=BD=91?= =?UTF-8?q?=E6=8E=A7=E7=94=B5=E9=87=8F=E5=91=8A=E8=AD=A6=E4=B8=8B=E9=99=90?= =?UTF-8?q?=E5=80=BC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fishery/controller/DeviceController.java | 106 ++++++++++++++++-- .../domain/bo/ReqSetBatteryWarnValue.java | 31 +++++ .../domain/bo/ReqSetOxyTempWarnCall.java | 2 +- 3 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 intc-modules/intc-fishery/src/main/java/com/intc/fishery/domain/bo/ReqSetBatteryWarnValue.java diff --git a/intc-modules/intc-fishery/src/main/java/com/intc/fishery/controller/DeviceController.java b/intc-modules/intc-fishery/src/main/java/com/intc/fishery/controller/DeviceController.java index 93a01cd..d6f5d6a 100644 --- a/intc-modules/intc-fishery/src/main/java/com/intc/fishery/controller/DeviceController.java +++ b/intc-modules/intc-fishery/src/main/java/com/intc/fishery/controller/DeviceController.java @@ -2,6 +2,7 @@ package com.intc.fishery.controller; import java.util.List; +import com.intc.fishery.domain.bo.*; import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.*; @@ -18,7 +19,6 @@ import com.intc.common.core.validate.EditGroup; import com.intc.common.log.enums.BusinessType; import com.intc.common.excel.utils.ExcelUtil; import com.intc.fishery.domain.vo.DeviceVo; -import com.intc.fishery.domain.bo.DeviceBo; import com.intc.fishery.service.IDeviceService; import com.intc.common.mybatis.core.page.TableDataInfo; import com.intc.fishery.domain.vo.PublicDeviceSimpleVo; @@ -28,14 +28,6 @@ import com.intc.fishery.domain.vo.PublicDeviceBaseData; import com.intc.fishery.domain.vo.PublicDeviceLinkedCtrl; import com.intc.fishery.domain.vo.PublicDeviceDeadInfo; import com.intc.fishery.domain.vo.PublicDeviceTypeAndSerialNum; -import com.intc.fishery.domain.bo.ReqId; -import com.intc.fishery.domain.bo.ReqSetOxyTempWarnCall; -import com.intc.fishery.domain.bo.ReqSetOxyWarnValue; -import com.intc.fishery.domain.bo.ReqSetTempWarnValue; -import com.intc.fishery.domain.bo.ReqDeviceCalibrate; -import com.intc.fishery.domain.bo.ReqDeviceSalinityCompensation; -import com.intc.fishery.domain.bo.ReqChangeName; -import com.intc.fishery.domain.bo.ReqTurnOpen; import com.intc.fishery.domain.Device; import com.intc.fishery.domain.DeviceSwitch; import com.intc.fishery.domain.Pond; @@ -463,7 +455,8 @@ public class DeviceController extends BaseController { .select(Device::getId, Device::getUserId, Device::getDeviceName, Device::getSerialNum, Device::getOxyWarnCallOpen, Device::getOxyWarnCallNoDis, Device::getTempWarnCallOpen, - Device::getTempWarnCallNoDis) + Device::getTempWarnCallNoDis, Device::getBatteryWarnCallOpen, + Device::getBatteryWarnCallNoDis) ); if (device == null || device.getUserId() == null || !device.getUserId().equals(rootUserId)) { @@ -536,8 +529,42 @@ public class DeviceController extends BaseController { return R.ok(); } + else if (request.getType() == 3) { + // 检查是否需要更新 + Long newOpen = request.getIsOpen().longValue(); + Long newNoDis = request.getIsNoDisturb().longValue(); + if (newOpen.equals(device.getBatteryWarnCallOpen()) + && newNoDis.equals(device.getBatteryWarnCallNoDis())) { + return R.ok(); + } + + // 更新低电量告警配置 + boolean updated = deviceMapper.update(null, + new LambdaUpdateWrapper() + .eq(Device::getId, request.getDeviceId()) + .set(Device::getBatteryWarnCallOpen, newOpen) + .set(Device::getBatteryWarnCallNoDis, newNoDis) + .set(Device::getBatteryWarnCallLastTime, new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000)) + ) > 0; + + if (!updated) { + return R.fail("更新失败"); + } + + // 记录操作日志 + MessageOpRecordUtil.addMessageOpRecordUser( + rootUserId, + "设备告警设置", + String.format("%s(%s) 低电量告警开关:%s, 免打扰开关:%s", + device.getDeviceName(), device.getSerialNum(), + request.getIsOpen() == 1 ? "打开" : "关闭", + request.getIsNoDisturb() == 1 ? "打开" : "关闭") + ); + + return R.ok(); + } else { - return R.fail("参数错误:类型必须为1或2"); + return R.fail("参数错误:类型必须为1、2或3"); } } @@ -671,6 +698,63 @@ public class DeviceController extends BaseController { return R.ok(); } + /** + * 设置低电量告警下限 + * + * @param rootUserId 用户ID + * @param request 请求对象 + * @return 操作结果 + */ + @PutMapping("/set_battery_warn_value") + public R setBatteryWarnValue( + @RequestParam("rootUserId") Long rootUserId, + @Validated @RequestBody ReqSetBatteryWarnValue request) { + + // 查询设备信息 + Device device = deviceMapper.selectOne( + new LambdaQueryWrapper() + .eq(Device::getId, request.getDeviceId()) + .select(Device::getDeviceName, Device::getSerialNum, Device::getUserId, + Device::getBatteryWarnLower, Device::getDeadTime) + ); + + if (device == null || device.getUserId() == null || !device.getUserId().equals(rootUserId)) { + return R.fail("设备不存在或无权限操作"); + } + + // 检查设备是否过期 + if (device.getDeadTime() != null && device.getDeadTime().before(new Date())) { + return R.fail("设备服务已过期"); + } + + // 保存旧值用于日志记录 + Long oldValue = device.getBatteryWarnLower(); + + // 更新低电量告警下限 + boolean updated = deviceMapper.update(null, + new LambdaUpdateWrapper() + .eq(Device::getId, request.getDeviceId()) + .set(Device::getBatteryWarnLower, request.getBatteryWarnLower()) + ) > 0; + + if (!updated) { + return R.fail("更新失败"); + } + + // 记录操作日志(仅当值发生变化时) + if (oldValue == null || !oldValue.equals(request.getBatteryWarnLower())) { + MessageOpRecordUtil.addMessageOpRecordUser( + rootUserId, + "设备告警値设置", + String.format("%s(%s) 设置低电量告警下限:%s%%", + device.getDeviceName(), device.getSerialNum(), + request.getBatteryWarnLower()) + ); + } + + return R.ok(); + } + /** * 获取设备饱和度 * diff --git a/intc-modules/intc-fishery/src/main/java/com/intc/fishery/domain/bo/ReqSetBatteryWarnValue.java b/intc-modules/intc-fishery/src/main/java/com/intc/fishery/domain/bo/ReqSetBatteryWarnValue.java new file mode 100644 index 0000000..4891766 --- /dev/null +++ b/intc-modules/intc-fishery/src/main/java/com/intc/fishery/domain/bo/ReqSetBatteryWarnValue.java @@ -0,0 +1,31 @@ +package com.intc.fishery.domain.bo; + +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 设置低电量告警下限请求对象 + * + * @author intc + */ +@Data +public class ReqSetBatteryWarnValue implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 设备ID + */ + @NotNull(message = "设备ID不能为空") + private Long deviceId; + + /** + * 低电量告警下限(百分比,0-100) + */ + @NotNull(message = "低电量告警下限不能为空") + private Long batteryWarnLower; +} diff --git a/intc-modules/intc-fishery/src/main/java/com/intc/fishery/domain/bo/ReqSetOxyTempWarnCall.java b/intc-modules/intc-fishery/src/main/java/com/intc/fishery/domain/bo/ReqSetOxyTempWarnCall.java index fe70160..bc904bb 100644 --- a/intc-modules/intc-fishery/src/main/java/com/intc/fishery/domain/bo/ReqSetOxyTempWarnCall.java +++ b/intc-modules/intc-fishery/src/main/java/com/intc/fishery/domain/bo/ReqSetOxyTempWarnCall.java @@ -25,7 +25,7 @@ public class ReqSetOxyTempWarnCall implements Serializable { private Long deviceId; /** - * 类型(1-溶解氧告警,2-温度告警) + * 类型(1-溶解氧告警,2-温度告警,3-低电量告警) */ @NotNull(message = "类型不能为空") private Integer type;