0918优化-点位列表数据值反向搜索
This commit is contained in:
@ -9,6 +9,7 @@ import com.xzzn.common.enums.DeviceCategory;
|
|||||||
import com.xzzn.common.utils.DateUtils;
|
import com.xzzn.common.utils.DateUtils;
|
||||||
import com.xzzn.common.utils.StringUtils;
|
import com.xzzn.common.utils.StringUtils;
|
||||||
import com.xzzn.ems.domain.EmsDevicesSetting;
|
import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||||
|
import com.xzzn.ems.domain.vo.PointDataRequest;
|
||||||
import com.xzzn.ems.domain.vo.PointQueryResponse;
|
import com.xzzn.ems.domain.vo.PointQueryResponse;
|
||||||
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
|
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
|
||||||
import com.xzzn.ems.mapper.EmsPointMatchMapper;
|
import com.xzzn.ems.mapper.EmsPointMatchMapper;
|
||||||
@ -16,6 +17,7 @@ import com.xzzn.ems.service.IEmsDeviceSettingService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -120,10 +122,13 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PointQueryResponse> getSingleSiteDevicePoints(String siteId, String deviceId,
|
public List<PointQueryResponse> getSingleSiteDevicePoints(PointDataRequest request) {
|
||||||
String deviceCategory, String dataPointName,
|
String siteId = request.getSiteId();
|
||||||
String dataPoint, String sortMethod) {
|
String deviceId = request.getDeviceId();
|
||||||
List<PointQueryResponse> response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,dataPointName,dataPoint);
|
String deviceCategory = request.getDeviceCategory();
|
||||||
|
|
||||||
|
List<PointQueryResponse> response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,
|
||||||
|
request.getDataPointName(),request.getDataPoint());
|
||||||
|
|
||||||
// 电动所的电池簇特殊处理-来源pcs+bmsd
|
// 电动所的电池簇特殊处理-来源pcs+bmsd
|
||||||
if (siteId.equals(DDS_SITE_ID) && DeviceCategory.CLUSTER.getCode().equals(deviceCategory)) {
|
if (siteId.equals(DDS_SITE_ID) && DeviceCategory.CLUSTER.getCode().equals(deviceCategory)) {
|
||||||
@ -158,7 +163,30 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|||||||
if (response == null || response.isEmpty()) {
|
if (response == null || response.isEmpty()) {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
BigDecimal lowerBound = request.getLower();
|
||||||
|
BigDecimal upperBound = request.getUpper();
|
||||||
|
// 数据反向筛选
|
||||||
|
if (lowerBound == null && upperBound == null) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
response = response.stream() .filter(point -> {
|
||||||
|
Object dataValue = point.getPointValue();
|
||||||
|
if (dataValue == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 转换为BigDecimal进行精确比较(避免double精度损失)
|
||||||
|
BigDecimal value = parseToBigDecimal(dataValue);
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 比较:使用BigDecimal的compareTo方法
|
||||||
|
boolean meetLower = (lowerBound == null) || (value.compareTo(lowerBound) >= 0);
|
||||||
|
boolean meetUpper = (upperBound == null) || (value.compareTo(upperBound) <= 0);
|
||||||
|
return meetLower && meetUpper;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
// 结果排序
|
// 结果排序
|
||||||
|
String sortMethod = request.getSortMethod();
|
||||||
if (sortMethod==null || sortMethod.isEmpty() || "asc".equals(sortMethod)) {// 升序
|
if (sortMethod==null || sortMethod.isEmpty() || "asc".equals(sortMethod)) {// 升序
|
||||||
response = response.stream().sorted(Comparator.comparing(PointQueryResponse::getUpdateTime)).collect(Collectors.toList());
|
response = response.stream().sorted(Comparator.comparing(PointQueryResponse::getUpdateTime)).collect(Collectors.toList());
|
||||||
} else if ("desc".equals(sortMethod)) {//降序
|
} else if ("desc".equals(sortMethod)) {//降序
|
||||||
@ -167,6 +195,23 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Object转BigDecimal(支持多种类型)
|
||||||
|
private BigDecimal parseToBigDecimal(Object dataValue) {
|
||||||
|
if (dataValue instanceof BigDecimal) {
|
||||||
|
return (BigDecimal) dataValue;
|
||||||
|
} else if (dataValue instanceof Number) {
|
||||||
|
return new BigDecimal(((Number) dataValue).toString());
|
||||||
|
} else if (dataValue instanceof String) {
|
||||||
|
try {
|
||||||
|
return new BigDecimal((String) dataValue);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 对于dds的电池簇点位最新数据获取特殊处理
|
// 对于dds的电池簇点位最新数据获取特殊处理
|
||||||
private List<PointQueryResponse> specialDealWithDDSCluster(List<PointQueryResponse> response, String siteId, String deviceId) {
|
private List<PointQueryResponse> specialDealWithDDSCluster(List<PointQueryResponse> response, String siteId, String deviceId) {
|
||||||
JSONObject mergedData = new JSONObject();
|
JSONObject mergedData = new JSONObject();
|
||||||
|
|||||||
Reference in New Issue
Block a user