getRealTimeDataByDevicerId接口数据第一版
This commit is contained in:
parent
47a00e60e8
commit
c4a03a4d44
@ -54,7 +54,9 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
|
||||
|
||||
@Override
|
||||
public GisDeviceListVo totalAndList(Device device) {
|
||||
List<Product> productEntities = productMapper.selectProductList(new Product());
|
||||
Product product = new Product();
|
||||
product.setProductId(136L);
|
||||
List<Product> productEntities = productMapper.selectProductList(product);
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
List<TreeItemVo> productContainDeviceListVos = new ArrayList<>();
|
||||
int count = 0;
|
||||
@ -99,8 +101,7 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
|
||||
|
||||
@Override
|
||||
public Object getRealTimeDataByDevicerId(Long deviceId) {
|
||||
HashMap<String, Object> rMap = new HashMap<String, Object>() {
|
||||
};
|
||||
HashMap<String, Object> rMap = new HashMap<String, Object>() {};
|
||||
if (deviceId == null) {
|
||||
throw new RuntimeException("请上传devicerId");
|
||||
}
|
||||
@ -108,62 +109,104 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
|
||||
if (device == null) {
|
||||
throw new RuntimeException("未查到该设备");
|
||||
}
|
||||
ThingsModel thingsModel1 = new ThingsModel();
|
||||
thingsModel1.setProductId(device.getProductId());
|
||||
List<ThingsModel> thingsModelEntities = thingsModelService.selectThingsModelList(thingsModel1);
|
||||
// List<ThingsModelValueItem> thingsModelValueItems = deviceInfoCacheService.getDeviceInfoCache(device.getDeviceId());
|
||||
// List<ThingsModelValueItem> thingsModelValueItems = deviceInfoCacheService.getCacheDeviceStatus(device.getProductId(),
|
||||
// device.getSerialNumber());
|
||||
DateTime dateTime = DateUtil.date(new Date());
|
||||
List<DeviceLog> deviceLogsAll = new ArrayList<>();
|
||||
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
|
||||
setSerialNumber(device.getSerialNumber());
|
||||
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
|
||||
setEndTime(DateUtil.endOfDay(dateTime).toString());
|
||||
}});
|
||||
if (deviceLogs != null) {
|
||||
deviceLogsAll.addAll(deviceLogs);
|
||||
}
|
||||
|
||||
Map<String, List<DeviceLog>> collect = deviceLogsAll.stream().sorted(Comparator
|
||||
.comparing(DeviceLog::getCreateTime, Comparator
|
||||
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
|
||||
for (ThingsModel thingsModel : thingsModelEntities) {
|
||||
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
|
||||
put("upType", 0);
|
||||
put("identifier", thingsModel.getIdentifier());
|
||||
put("unit", "");
|
||||
put("value", 0);
|
||||
put("name", thingsModel.getModelName());
|
||||
}};
|
||||
// {"max": 100, "min": 0, "step": 1, "type": "decimal", "unit": "m/s"}
|
||||
if(StringUtils.isNotEmpty(thingsModel.getSpecs())){
|
||||
String specs = thingsModel.getSpecs();
|
||||
JSONObject parse = (JSONObject) JSON.parse(specs);
|
||||
if(parse.containsKey("unit")){
|
||||
hashMap.put("unit", parse.get("unit"));
|
||||
}
|
||||
}
|
||||
|
||||
if (hashMap.size() > 1) {
|
||||
List<DeviceLog> deviceLogs1 = collect.get(thingsModel.getIdentifier());
|
||||
if (deviceLogs1 != null) {
|
||||
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue()))
|
||||
{
|
||||
hashMap.put("upType", 1);
|
||||
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
|
||||
hashMap.put("upType", -1);
|
||||
Map<String, Object> devParams = getDevParams(device);
|
||||
//太阳能设备
|
||||
String taiyangnengIds = devParams.get("taiyangnIds").toString();
|
||||
ThingsModel thingsModel1 = new ThingsModel();
|
||||
thingsModel1.setProductId(138L);
|
||||
List<ThingsModel> taiyangnengModels = thingsModelService.selectThingsModelList(thingsModel1);
|
||||
// HashMap<String, Object> taiyangnengMap = new HashMap<String, Object>() {};
|
||||
if (StringUtils.isNotEmpty(taiyangnengIds)) {
|
||||
Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(taiyangnengIds));
|
||||
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
|
||||
setSerialNumber(taiyangnengDevice.getSerialNumber());
|
||||
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
|
||||
setEndTime(DateUtil.endOfDay(dateTime).toString());
|
||||
}});
|
||||
Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
|
||||
.comparing(DeviceLog::getCreateTime, Comparator
|
||||
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
|
||||
for (ThingsModel thingsModel : taiyangnengModels) {
|
||||
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
|
||||
put("upType", 0);
|
||||
put("identifier", thingsModel.getIdentifier());
|
||||
put("unit", "");
|
||||
put("value", 0);
|
||||
put("name", thingsModel.getModelName());
|
||||
}};
|
||||
if(StringUtils.isNotEmpty(thingsModel.getSpecs())){
|
||||
String specs = thingsModel.getSpecs();
|
||||
JSONObject parse = (JSONObject) JSON.parse(specs);
|
||||
if(parse.containsKey("unit")){
|
||||
hashMap.put("unit", parse.get("unit"));
|
||||
}
|
||||
hashMap.put("value", deviceLogs1.get(0).getLogValue());
|
||||
}
|
||||
} else if (hashMap.size() > 0) {
|
||||
List<DeviceLog> deviceLogs2 = collect.get(thingsModel.getIdentifier());
|
||||
if (deviceLogs2 != null) {
|
||||
hashMap.put("value", deviceLogs2.get(0).getLogValue());
|
||||
|
||||
if (hashMap.size() > 1) {
|
||||
List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
|
||||
if (deviceLogs1 != null) {
|
||||
if(StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())){
|
||||
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue()))
|
||||
{
|
||||
hashMap.put("upType", 1);
|
||||
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
|
||||
hashMap.put("upType", -1);
|
||||
}
|
||||
hashMap.put("value", deviceLogs1.get(0).getLogValue());
|
||||
}else{
|
||||
hashMap.put("value", "--");
|
||||
hashMap.put("upType", 0);
|
||||
}
|
||||
|
||||
}
|
||||
} else if (hashMap.size() > 0) {
|
||||
List<DeviceLog> deviceLogs2 = taiyangnengCollect.get(thingsModel.getIdentifier());
|
||||
if (deviceLogs2 != null) {
|
||||
hashMap.put("value", deviceLogs2.get(0).getLogValue());
|
||||
}
|
||||
}
|
||||
rMap.put(thingsModel.getIdentifier(), hashMap);
|
||||
}
|
||||
}else{
|
||||
for (ThingsModel thingsModel : taiyangnengModels){
|
||||
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
|
||||
put("upType", 0);
|
||||
put("identifier", thingsModel.getIdentifier());
|
||||
put("unit", "");
|
||||
put("value", 0);
|
||||
put("name", thingsModel.getModelName());
|
||||
}};
|
||||
rMap.put(thingsModel.getIdentifier(), hashMap);
|
||||
}
|
||||
rMap.put(thingsModel.getIdentifier(), hashMap);
|
||||
}
|
||||
//安防信息
|
||||
String anfangIds = devParams.get("anfangIds").toString();
|
||||
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
|
||||
put("upType", 0);
|
||||
put("identifier", "xiangmen");
|
||||
put("unit", "");
|
||||
put("value", 0);//0=正常,1=箱门振动,2=箱门打开
|
||||
put("name", "箱门状态");
|
||||
}};
|
||||
rMap.put("xiangmen",hashMap);
|
||||
//机井信息
|
||||
HashMap<Object, Object> hashMap1 = new HashMap<Object, Object>() {{
|
||||
put("upType", 0);
|
||||
put("identifier", "sumFlow");
|
||||
put("unit", "m³");
|
||||
put("value", 0);
|
||||
put("name", "累计用水量");
|
||||
}};
|
||||
rMap.put("sumFlow",hashMap1);
|
||||
HashMap<Object, Object> hashMap2 = new HashMap<Object, Object>() {{
|
||||
put("upType", 0);
|
||||
put("identifier", "sumEle");
|
||||
put("unit", "度");
|
||||
put("value", 0);
|
||||
put("name", "累计用电量");
|
||||
}};
|
||||
rMap.put("sumEle",hashMap2);
|
||||
return rMap;
|
||||
}
|
||||
|
||||
@ -257,4 +300,20 @@ public class GisDeviceServiceImpl implements IGisDeviceService {
|
||||
|
||||
}
|
||||
|
||||
public Map<String, Object> getDevParams(Device device) {
|
||||
Map<String, Object> devData = new HashMap<>();
|
||||
try{
|
||||
Object devParams = com.alibaba.fastjson.JSON.parse(device.getDevParams()); //先转换成Object
|
||||
List<Map<String, Object>> Params = (List<Map<String, Object>>) devParams;
|
||||
if (Params != null) {
|
||||
for (Map<String, Object> param : Params) {
|
||||
devData.put(param.get("key").toString(), param.get("value").toString());
|
||||
}
|
||||
}
|
||||
}catch (Exception exception){
|
||||
}
|
||||
|
||||
return devData;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1600,6 +1600,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
@Override
|
||||
public List<Map<String, Object>> devicePointInfo(Device devices) {
|
||||
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
|
||||
devices.setProductId(136L);
|
||||
List<Device> deviceList = selectDeviceList(devices);
|
||||
|
||||
for (Device device : deviceList) {
|
||||
|
@ -88,7 +88,7 @@ public class ThingsModelServiceImpl implements IThingsModelService {
|
||||
*/
|
||||
@Override
|
||||
public ThingsModel selectSingleThingsModel(ThingsModel model) {
|
||||
model.setLanguage(SecurityUtils.getLanguage());
|
||||
// model.setLanguage(SecurityUtils.getLanguage());
|
||||
return thingsModelMapper.selectSingleThingsModel(model);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user