0918优化-点位列表排序方式,默认升序
This commit is contained in:
@ -147,10 +147,11 @@ public class EmsSiteConfigController extends BaseController{
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/getDevicePointList")
|
@GetMapping("/getDevicePointList")
|
||||||
public TableDataInfo getDevicePointList(@RequestParam String siteId,@RequestParam String deviceId,
|
public TableDataInfo getDevicePointList(@RequestParam String siteId,@RequestParam String deviceId,
|
||||||
@RequestParam String deviceCategory, String dataPointName,
|
@RequestParam String deviceCategory, String sortMethod,
|
||||||
String dataPoint)
|
String dataPointName, String dataPoint)
|
||||||
{
|
{
|
||||||
List<PointQueryResponse> result = iEmsDeviceSettingService.getSingleSiteDevicePoints(siteId,deviceId,deviceCategory,dataPointName,dataPoint);
|
List<PointQueryResponse> result = iEmsDeviceSettingService.getSingleSiteDevicePoints(
|
||||||
|
siteId,deviceId,deviceCategory,dataPointName,dataPoint,sortMethod);
|
||||||
return getDataTable2(result);
|
return getDataTable2(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,5 +25,5 @@ public interface IEmsDeviceSettingService
|
|||||||
public List<DeviceCategory> getDeviceCategory();
|
public List<DeviceCategory> getDeviceCategory();
|
||||||
|
|
||||||
public List<PointQueryResponse> getSingleSiteDevicePoints(String siteId, String deviceId, String deviceCategory,
|
public List<PointQueryResponse> getSingleSiteDevicePoints(String siteId, String deviceId, String deviceCategory,
|
||||||
String dataPointName, String dataPoint);
|
String dataPointName, String dataPoint, String sortMethod);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 站点信息 服务层实现
|
* 站点信息 服务层实现
|
||||||
@ -120,41 +121,49 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PointQueryResponse> getSingleSiteDevicePoints(String siteId, String deviceId,
|
public List<PointQueryResponse> getSingleSiteDevicePoints(String siteId, String deviceId,
|
||||||
String deviceCategory, String dataPointName,String dataPoint) {
|
String deviceCategory, String dataPointName,
|
||||||
|
String dataPoint, String sortMethod) {
|
||||||
List<PointQueryResponse> response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,dataPointName,dataPoint);
|
List<PointQueryResponse> response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,dataPointName,dataPoint);
|
||||||
|
|
||||||
// 电动所的电池簇特殊处理-来源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)) {
|
||||||
response = specialDealWithDDSCluster(response,siteId,deviceId);
|
response = specialDealWithDDSCluster(response,siteId,deviceId);
|
||||||
return response;
|
} else {
|
||||||
}
|
// 从redis取最新数据
|
||||||
|
JSONObject mqttJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId);
|
||||||
// 从redis取最新数据
|
if(mqttJson == null){
|
||||||
//String test = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId);
|
return response;
|
||||||
JSONObject mqttJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId);
|
}
|
||||||
if(mqttJson == null){
|
String deviceFromMqtt = mqttJson.get("Device").toString();
|
||||||
return response;
|
String jsonData = mqttJson.get("Data").toString();
|
||||||
}
|
if (StringUtils.isEmpty(jsonData) || !deviceId.equals(deviceFromMqtt)) {
|
||||||
String deviceFromMqtt = mqttJson.get("Device").toString();
|
return response;
|
||||||
String jsonData = mqttJson.get("Data").toString();
|
}
|
||||||
if (StringUtils.isEmpty(jsonData) || !deviceId.equals(deviceFromMqtt)) {
|
|
||||||
return response;
|
Map<String, Object> obj = JSON.parseObject(jsonData, new TypeReference<Map<String, Object>>() {});
|
||||||
}
|
for (PointQueryResponse pointInfo : response) {
|
||||||
|
String dataKey = pointInfo.getDataPoint();
|
||||||
Map<String, Object> obj = JSON.parseObject(jsonData, new TypeReference<Map<String, Object>>() {});
|
int isNeedDeviceId = pointInfo.getIsNeedDeviceId();
|
||||||
for (PointQueryResponse pointInfo : response) {
|
if (isNeedDeviceId == 1) {// 需要根据deviceId拼接point
|
||||||
String dataKey = pointInfo.getDataPoint();
|
dataKey = deviceId + dataKey;
|
||||||
int isNeedDeviceId = pointInfo.getIsNeedDeviceId();
|
pointInfo.setDataPoint(dataKey);
|
||||||
if (isNeedDeviceId == 1) {// 需要根据deviceId拼接point
|
}
|
||||||
dataKey = deviceId + dataKey;
|
pointInfo.setPointValue(obj.get(dataKey));
|
||||||
pointInfo.setDataPoint(dataKey);
|
Long updateTime = Long.valueOf(mqttJson.get("timestamp").toString());
|
||||||
|
Date latestUpdateTime = convertUpdateTime(updateTime);
|
||||||
|
pointInfo.setUpdateTime(latestUpdateTime);
|
||||||
}
|
}
|
||||||
pointInfo.setPointValue(obj.get(dataKey));
|
|
||||||
Long updateTime = Long.valueOf(mqttJson.get("timestamp").toString());
|
|
||||||
Date latestUpdateTime = convertUpdateTime(updateTime);
|
|
||||||
pointInfo.setUpdateTime(latestUpdateTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response == null || response.isEmpty()) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
// 结果排序
|
||||||
|
if (sortMethod==null || sortMethod.isEmpty() || "asc".equals(sortMethod)) {// 升序
|
||||||
|
response = response.stream().sorted(Comparator.comparing(PointQueryResponse::getUpdateTime)).collect(Collectors.toList());
|
||||||
|
} else if ("desc".equals(sortMethod)) {//降序
|
||||||
|
response = response.stream().sorted(Comparator.comparing(PointQueryResponse::getUpdateTime).reversed()).collect(Collectors.toList());
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user