fix: 太阳能控制下发指令,自测bug修复。
This commit is contained in:
@@ -336,12 +336,17 @@ public class DeviceVo implements Serializable {
|
||||
@ExcelProperty(value = "用户名")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 塘口名称
|
||||
*/
|
||||
@ExcelProperty(value = "塘口名称")
|
||||
private String pondName;
|
||||
|
||||
/**
|
||||
* 设备在线状态(online/offline)
|
||||
*/
|
||||
private String onlineStatus;
|
||||
|
||||
/**
|
||||
* 是否过期(0-未过期,1-已过期)
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.intc.common.core.config.properties.DeviceTypeProperties;
|
||||
import com.intc.common.core.utils.MapstructUtils;
|
||||
import com.intc.common.core.utils.StringUtils;
|
||||
import com.intc.common.mybatis.core.page.PageQuery;
|
||||
@@ -60,11 +61,22 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
private final DeviceSwitchMapper deviceSwitchMapper;
|
||||
private final LinkedCtrlMapper linkedCtrlMapper;
|
||||
private final TimingCtrlMapper timingCtrlMapper;
|
||||
private final DeviceTypeProperties deviceTypeProperties;
|
||||
|
||||
/** Redis 离线等待标记前缀(与 DeviceDataHandler 保持一致) */
|
||||
private static final String DEVICE_OFFLINE_WAIT_KEY_PREFIX = "device:offline:wait:";
|
||||
/** Redis 溶解氧探头离线等待标记前缀 */
|
||||
private static final String DETECTOR_OXY_OFFLINE_WAIT_KEY_PREFIX = "device:detector:oxy:offline:wait:";
|
||||
/** 太阳能网控设备类型 */
|
||||
private static final Integer DEVICE_TYPE_SOLAR_CONTROLLER = 3;
|
||||
/** 设备在线状态表别名 */
|
||||
private static final String DEVICE_STATUS_ALIAS = "ids";
|
||||
/** 设备在线状态表状态字段 */
|
||||
private static final String DEVICE_STATUS_COLUMN = DEVICE_STATUS_ALIAS + ".status";
|
||||
/** 设备在线状态展示字段 */
|
||||
private static final String DEVICE_STATUS_DISPLAY_COLUMN = "LOWER(COALESCE(" + DEVICE_STATUS_COLUMN + ", 'offline'))";
|
||||
/** 设备在线状态表状态字段(小写) */
|
||||
private static final String DEVICE_STATUS_LOWER_COLUMN = "LOWER(" + DEVICE_STATUS_COLUMN + ")";
|
||||
|
||||
/**
|
||||
* 查询设备管理
|
||||
@@ -115,6 +127,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
private MPJLambdaWrapper<Device> buildQueryWrapper(DeviceBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
MPJLambdaWrapper<Device> wrapper = new MPJLambdaWrapper<>();
|
||||
boolean solarQuery = DEVICE_TYPE_SOLAR_CONTROLLER.equals(bo.getDeviceType());
|
||||
|
||||
// Select main table fields
|
||||
wrapper.selectAll(Device.class);
|
||||
@@ -127,6 +140,12 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
wrapper.leftJoin(AquUser.class, AquUser::getId, Device::getUserId);
|
||||
// Left join with pond table
|
||||
wrapper.leftJoin(Pond.class, Pond::getId, Device::getPondId);
|
||||
if (solarQuery) {
|
||||
wrapper.selectAs(DEVICE_STATUS_DISPLAY_COLUMN, DeviceVo::getOnlineStatus)
|
||||
.leftJoin(buildSolarStatusJoinSql());
|
||||
applySolarOnlineStatusFilter(wrapper, params);
|
||||
wrapper.orderByAsc("CASE WHEN " + DEVICE_STATUS_LOWER_COLUMN + " = 'online' THEN 0 ELSE 1 END");
|
||||
}
|
||||
|
||||
// 处理排序逼辑:如果expiredFlag为1,按过期时间倒序,否则按创建时间倒序
|
||||
String expiredFlag = params != null ? (String) params.get("expiredFlag") : null;
|
||||
@@ -154,6 +173,33 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private String buildSolarStatusJoinSql() {
|
||||
String sql = "iot_device_status " + DEVICE_STATUS_ALIAS + " ON "
|
||||
+ DEVICE_STATUS_ALIAS + ".device_name = t.serial_num";
|
||||
String productKey = deviceTypeProperties.getSolarController();
|
||||
if (StringUtils.isNotBlank(productKey)) {
|
||||
sql += " AND " + DEVICE_STATUS_ALIAS + ".product_key = '" + productKey.replace("'", "''") + "'";
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* 太阳能网控在线状态查询。
|
||||
*/
|
||||
private void applySolarOnlineStatusFilter(MPJLambdaWrapper<Device> wrapper, Map<String, Object> params) {
|
||||
if (params == null || params.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String onlineStatus = params.get("onlineStatus") != null ? params.get("onlineStatus").toString() : null;
|
||||
if ("online".equalsIgnoreCase(onlineStatus)) {
|
||||
wrapper.apply(DEVICE_STATUS_LOWER_COLUMN + " = {0}", "online");
|
||||
} else if ("offline".equalsIgnoreCase(onlineStatus)) {
|
||||
wrapper.and(w -> w.isNull(DEVICE_STATUS_COLUMN)
|
||||
.or()
|
||||
.apply(DEVICE_STATUS_LOWER_COLUMN + " <> {0}", "online"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理额外的查询参数
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user