Browse Source

commit code

master
刘力 3 years ago
parent
commit
791c9eeb62
  1. 27
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/controller/AlarmInfoController.java
  2. 62
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/domain/GetCurAlarm.java
  3. 7
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/AlarmInfoService.java
  4. 3
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/ThirdApiService.java
  5. 41
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/AlarmInfoServiceImpl.java
  6. 24
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/ThirdApiServiceImpl.java

27
storeroom/src/main/java/com/storeroom/modules/storeroom3d/controller/AlarmInfoController.java

@ -0,0 +1,27 @@
package com.storeroom.modules.storeroom3d.controller;
import com.storeroom.annotaion.rest.AnonymousGetMapping;
import com.storeroom.modules.storeroom3d.service.AlarmInfoService;
import com.storeroom.utils.ApiResponse;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/alarm/")
@Api(tags = "测试第三方接口")
@RequiredArgsConstructor
public class AlarmInfoController {
private final AlarmInfoService alarmInfoService;
@AnonymousGetMapping("all")
public ApiResponse<Object> queryAllAlarm() {
return ApiResponse.success(alarmInfoService.getAllAlarmInfo());
}
}

62
storeroom/src/main/java/com/storeroom/modules/storeroom3d/domain/GetCurAlarm.java

@ -0,0 +1,62 @@
package com.storeroom.modules.storeroom3d.domain;
import com.storeroom.base.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
@Entity
@Getter
@Setter
@Table(name = "get_cur_alarm")
public class GetCurAlarm implements Serializable {
@Id
@Column(name = "event_id")
@NotNull(groups = BaseEntity.Update.class)
@ApiModelProperty(value = "警告id", hidden = true)
private String event_id;
@Column(name = "event_name")
@ApiModelProperty(value = "告警名称",hidden = true)
private String event_name;
@Column(name = "device_id")
@ApiModelProperty(value = "设备ID",hidden = true)
private String device_id;
@Column(name = "device_name")
@ApiModelProperty(value = "设备名称",hidden = true)
private String device_name;
@Column(name = "category_name")
@ApiModelProperty(value = "分类名称",hidden = true)
private String category_name;
@Column(name = "area_name")
@ApiModelProperty(value = "区域名称",hidden = true)
private String area_name;
@Column(name = "event_level_name")
@ApiModelProperty(value = "告警等级",hidden = true)
private String event_level_name;
@Column(name = "alarm_time")
@ApiModelProperty(value = "更新时间",hidden = true)
private Timestamp alarm_time;
@Column(name = "alarm_value")
@ApiModelProperty(value = "告警值",hidden = true)
private String alarm_value;
}

7
storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/AlarmInfoService.java

@ -0,0 +1,7 @@
package com.storeroom.modules.storeroom3d.service;
public interface AlarmInfoService {
Object getAllAlarmInfo();
}

3
storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/ThirdApiService.java

@ -1,6 +1,7 @@
package com.storeroom.modules.storeroom3d.service; package com.storeroom.modules.storeroom3d.service;
import com.storeroom.modules.storeroom3d.service.dto.DeviceAllDto; import com.storeroom.modules.storeroom3d.service.dto.DeviceAllDto;
import com.storeroom.modules.storeroom3d.service.dto.GetCurAlarmDto;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -25,7 +26,7 @@ public interface ThirdApiService {
* 获取所有设备报警信息 * 获取所有设备报警信息
* @return * @return
*/ */
Object getAllDeviceAlarm();
List<GetCurAlarmDto> getAllDeviceAlarm();
/** /**

41
storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/AlarmInfoServiceImpl.java

@ -0,0 +1,41 @@
package com.storeroom.modules.storeroom3d.service.impl;
import com.storeroom.modules.device.domain.DeviceInfo;
import com.storeroom.modules.device.repository.DeviceInfoRepository;
import com.storeroom.modules.storeroom3d.service.AlarmInfoService;
import com.storeroom.modules.storeroom3d.service.ThirdApiService;
import com.storeroom.modules.storeroom3d.service.dto.GetCurAlarmDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class AlarmInfoServiceImpl implements AlarmInfoService {
private final DeviceInfoRepository deviceInfoRepository;
private final ThirdApiService thirdApiService;
@Override
public Object getAllAlarmInfo() {
List<DeviceInfo> deviceInfoList = deviceInfoRepository.findAll();
List<GetCurAlarmDto> alarmDtos = thirdApiService.getAllDeviceAlarm();
List<GetCurAlarmDto> alarmDtos1 = new ArrayList<>();
List<GetCurAlarmDto> alarmDtos2 = alarmDtos.stream().filter(getCurAlarmDto -> Objects.equals(getCurAlarmDto.getDevice_id(), "")).collect(Collectors.toList());
for (int i = 0; i < alarmDtos2.size(); i++) {
for (int k = 0; k < deviceInfoList.size(); k++) {
if (Objects.equals(alarmDtos.get(i).getDevice_id(), deviceInfoList.get(k).getDeviceId())) {
alarmDtos1.add(alarmDtos.get(i));
}
}
}
return alarmDtos1;
}
}

24
storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/ThirdApiServiceImpl.java

@ -104,7 +104,7 @@ public class ThirdApiServiceImpl implements ThirdApiService {
@SneakyThrows @SneakyThrows
@Override @Override
public Object getAllDeviceAlarm() {
public List<GetCurAlarmDto> getAllDeviceAlarm() {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
String token = findApiToken(); String token = findApiToken();
map.put("Content-type", "application/json"); map.put("Content-type", "application/json");
@ -121,16 +121,16 @@ public class ThirdApiServiceImpl implements ThirdApiService {
for (int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
GetCurAlarmDto getCurAlarmDto = new GetCurAlarmDto(); GetCurAlarmDto getCurAlarmDto = new GetCurAlarmDto();
JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject jsonObject = jsonArray.getJSONObject(i);
getCurAlarmDto.setDevice_id(jsonObject.get("device_id") == null ? "" : jsonObject.get("device_id").toString());
getCurAlarmDto.setAlarm_value(jsonObject.get("alarm_value") == null ? "" : jsonObject.get("alarm_value").toString());
getCurAlarmDto.setArea_name(jsonObject.get("area_name") == null ? "" : jsonObject.get("area_name").toString());
getCurAlarmDto.setEvent_id(jsonObject.get("event_id") == null ? "" : jsonObject.get("event_id").toString());
getCurAlarmDto.setEvent_level_name(jsonObject.get("event_level_name") == null ? "" : jsonObject.get("event_level_name").toString());
getCurAlarmDto.setAlarm_time(jsonObject.get("alarm_time") == null ? "" : jsonObject.get("alarm_time").toString());
getCurAlarmDto.setCategory_name(jsonObject.get("category_name") == null ? "" : jsonObject.get("category_name").toString());
getCurAlarmDto.setAlarm_value_descript(jsonObject.get("alarm_value_descript") == null ? "" : jsonObject.get("alarm_value_descript").toString());
getCurAlarmDto.setDevice_name(jsonObject.get("device_name") == null ? "" : jsonObject.get("device_name").toString());
getCurAlarmDto.setEvent_name(jsonObject.get("event_name") == null ? "" : jsonObject.get("event_name").toString());
getCurAlarmDto.setDevice_id(jsonObject.get("device_id") == null ? null : jsonObject.get("device_id").toString());
getCurAlarmDto.setAlarm_value(jsonObject.get("alarm_value") == null ? null : jsonObject.get("alarm_value").toString());
getCurAlarmDto.setArea_name(jsonObject.get("area_name") == null ? null : jsonObject.get("area_name").toString());
getCurAlarmDto.setEvent_id(jsonObject.get("event_id") == null ? null : jsonObject.get("event_id").toString());
getCurAlarmDto.setEvent_level_name(jsonObject.get("event_level_name") == null ? null : jsonObject.get("event_level_name").toString());
getCurAlarmDto.setAlarm_time(jsonObject.get("alarm_time") == null ? null : jsonObject.get("alarm_time").toString());
getCurAlarmDto.setCategory_name(jsonObject.get("category_name") == null ? null : jsonObject.get("category_name").toString());
getCurAlarmDto.setAlarm_value_descript(jsonObject.get("alarm_value_descript") == null ? null : jsonObject.get("alarm_value_descript").toString());
getCurAlarmDto.setDevice_name(jsonObject.get("device_name") == null ? null : jsonObject.get("device_name").toString());
getCurAlarmDto.setEvent_name(jsonObject.get("event_name") == null ? null : jsonObject.get("event_name").toString());
list.add(getCurAlarmDto); list.add(getCurAlarmDto);
} }
} }
@ -138,7 +138,7 @@ public class ThirdApiServiceImpl implements ThirdApiService {
}); });
//PushServiceImpl pushService=new PushServiceImpl(); //PushServiceImpl pushService=new PushServiceImpl();
// pushService.pushMsgToAll(result); // pushService.pushMsgToAll(result);
return result;
return list;
} else { } else {
throw new BaseException("访问失败" + response.getStatusLine().getStatusCode() + ""); throw new BaseException("访问失败" + response.getStatusLine().getStatusCode() + "");
} }

Loading…
Cancel
Save