iscs v2
This commit is contained in:
parent
8663b12acc
commit
812058e0d4
@ -0,0 +1,38 @@
|
|||||||
|
package club.joylink.rtss.iscs.convert;
|
||||||
|
|
||||||
|
import com.google.protobuf.Timestamp;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class TimeProtoConvertor {
|
||||||
|
private static TimeZone timeZone;
|
||||||
|
|
||||||
|
//如"GMT+8"
|
||||||
|
@Value("${spring.jackson.time-zone}")
|
||||||
|
public void setZoneId(String zoneId) {
|
||||||
|
TimeProtoConvertor.timeZone = TimeZone.getTimeZone(ZoneId.of(zoneId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Timestamp.Builder convertFrom(LocalDateTime from) {
|
||||||
|
final Instant instant = from.toInstant(ZoneOffset.ofTotalSeconds(timeZone.getRawOffset() / 1000));
|
||||||
|
return Timestamp.newBuilder().setSeconds(instant.getEpochSecond()).setNanos(instant.getNano());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDateTime convertFrom(Timestamp from) {
|
||||||
|
return LocalDateTime.ofInstant(Instant.ofEpochSecond(from.getSeconds(), from.getNanos()), timeZone.toZoneId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final Timestamp.Builder timestamp = convertFrom(LocalDateTime.now());
|
||||||
|
System.out.println(timestamp.build().toString());
|
||||||
|
final LocalDateTime now = convertFrom(timestamp.build());
|
||||||
|
System.out.println(now.toString());
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +0,0 @@
|
|||||||
package club.joylink.rtss.iscs.convert;
|
|
||||||
|
|
||||||
import com.google.protobuf.Timestamp;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public class TimestampConvertor {
|
|
||||||
|
|
||||||
public static Timestamp.Builder convertFrom(Instant from){
|
|
||||||
return Timestamp.newBuilder().setSeconds(from.getEpochSecond()).setNanos(from.getNano());
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,14 +2,14 @@ package club.joylink.rtss.iscs.memory;
|
|||||||
|
|
||||||
|
|
||||||
import club.joylink.rtss.iscs.convert.PageDataModelConvertor;
|
import club.joylink.rtss.iscs.convert.PageDataModelConvertor;
|
||||||
|
import club.joylink.rtss.iscs.convert.TimeProtoConvertor;
|
||||||
import club.joylink.rtss.iscs.entity.IscsModelData;
|
import club.joylink.rtss.iscs.entity.IscsModelData;
|
||||||
import club.joylink.rtss.iscs.memory.model.ModelMemory;
|
import club.joylink.rtss.iscs.memory.model.ModelMemory;
|
||||||
import club.joylink.rtss.iscs.memory.model.ModelMemoryId;
|
import club.joylink.rtss.iscs.memory.model.ModelMemoryId;
|
||||||
import club.joylink.rtss.iscs.proto.model.data.PageDataModelProto;
|
import club.joylink.rtss.iscs.proto.model.data.PageDataModelProto;
|
||||||
import club.joylink.rtss.iscs.proto.model.status.soe.SoeProto;
|
import club.joylink.rtss.iscs.proto.model.status.soe.SoeProto;
|
||||||
import com.google.protobuf.Timestamp;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -31,21 +31,27 @@ public class MemoryManager {
|
|||||||
*/
|
*/
|
||||||
private LinkedList<SoeProto.AlarmEvent.Builder> alarmEvents = new LinkedList<>();
|
private LinkedList<SoeProto.AlarmEvent.Builder> alarmEvents = new LinkedList<>();
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/**
|
|
||||||
* 获取设备产生的动作事件
|
|
||||||
* <p>
|
|
||||||
* 查询条件:时间、场所、设备名称
|
|
||||||
*/
|
|
||||||
public SoeProto.ActionSoe.Builder getActionSoe(LocalDateTime startTime,LocalDateTime endTime,String place,String deviceName){
|
|
||||||
final boolean checkTime = endTime.isAfter(startTime);
|
|
||||||
final LocalDateTime start = checkTime?startTime:endTime;
|
|
||||||
final LocalDateTime end = checkTime?endTime:startTime;
|
|
||||||
final SoeProto.ActionSoe.Builder actSoe = SoeProto.ActionSoe.newBuilder();
|
|
||||||
actionEvents.forEach(actEvt->{
|
|
||||||
final Timestamp actStamp = actEvt.getCreateTime();
|
|
||||||
final LocalDateTime actTime = LocalDateTime.ofEpochSecond(actStamp.getSeconds(),actStamp.getNanos(), ZoneOffset.ofHours(8));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据条件过滤获取设备产生的动作事件
|
||||||
|
* <p>
|
||||||
|
* 查询条件:时间、场所、设备名称;
|
||||||
|
* 注意当设备名称为null时表示所有设备
|
||||||
|
*/
|
||||||
|
public SoeProto.ActionSoe.Builder getActionSoe(LocalDateTime startTime, LocalDateTime endTime, String place, String deviceName) {
|
||||||
|
final boolean checkTime = endTime.isAfter(startTime);
|
||||||
|
final LocalDateTime start = checkTime ? startTime : endTime;
|
||||||
|
final LocalDateTime end = checkTime ? endTime : startTime;
|
||||||
|
final SoeProto.ActionSoe.Builder actSoe = SoeProto.ActionSoe.newBuilder();
|
||||||
|
actionEvents.forEach(actEvt -> {
|
||||||
|
final LocalDateTime actTime = TimeProtoConvertor.convertFrom(actEvt.getCreateTime());
|
||||||
|
final boolean isTime = start.isEqual(end) ? actTime.isEqual(start) : (actTime.isAfter(start) && actTime.isBefore(end));
|
||||||
|
if (isTime && place.equals(actEvt.getPlace())) {
|
||||||
|
if (null == deviceName || deviceName.equals(actEvt.getDeviceName())) {
|
||||||
|
actSoe.addActions(actEvt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
return actSoe;
|
return actSoe;
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user