fix: 新增太阳能网控添加接口,设置太阳能网控电量告警下限值。
This commit is contained in:
@@ -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<Device>()
|
||||
.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<Void> setBatteryWarnValue(
|
||||
@RequestParam("rootUserId") Long rootUserId,
|
||||
@Validated @RequestBody ReqSetBatteryWarnValue request) {
|
||||
|
||||
// 查询设备信息
|
||||
Device device = deviceMapper.selectOne(
|
||||
new LambdaQueryWrapper<Device>()
|
||||
.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<Device>()
|
||||
.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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备饱和度
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class ReqSetOxyTempWarnCall implements Serializable {
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 类型(1-溶解氧告警,2-温度告警)
|
||||
* 类型(1-溶解氧告警,2-温度告警,3-低电量告警)
|
||||
*/
|
||||
@NotNull(message = "类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
Reference in New Issue
Block a user