Browse Source

新增时间工具类主要是Timestamp 格式的转换

master
刘力 3 years ago
parent
commit
056497f1a3
  1. 36
      common/src/main/java/com/storeroom/utils/TimestampTool.java
  2. 4
      storeroom/src/main/java/com/storeroom/modules/storeroom3d/service/impl/ThirdApiServiceImpl.java

36
common/src/main/java/com/storeroom/utils/TimestampTool.java

@ -1,6 +1,42 @@
package com.storeroom.utils;
import java.sql.Timestamp;
import java.util.Date;
public class TimestampTool {
/**
* 字符串转timestamp
* @param time /
* @return /
*/
public static Timestamp string2sqlTimestamp(String time){
Timestamp timestamp = Timestamp.valueOf(time);
System.out.println(timestamp.toString());
return timestamp;
}
/**
* timestamp 转字符串
* @param timestamp /
* @return /
*/
public static String sqlTimestamp2string(Timestamp timestamp){
return timestamp.toString();
}
/**
 * compare two util.Date ,if date1 is earlier return -1,equal return 0, later return 1
 */
public static int compareDate(Date date1, Date date2){
int result = date1.compareTo(date2);
return result;
}
/**
 * compare two sql.Timestamp ,if timestamp1 is earlier return -1,equal return 0, later return 1
 */
public static int compareTimestamp(Timestamp timestamp1,Timestamp timestamp2){
int result = timestamp1.compareTo(timestamp2);
return result;
}
}

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

@ -11,6 +11,7 @@ import com.storeroom.modules.storeroom3d.service.dto.RealTimeDataDto;
import com.storeroom.utils.FastjsonUtils;
import com.storeroom.utils.HttpUtils;
import com.storeroom.utils.RedisUtils;
import com.storeroom.utils.TimestampTool;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import okhttp3.*;
@ -127,8 +128,7 @@ public class ThirdApiServiceImpl implements ThirdApiService {
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());
Timestamp ts = Timestamp.valueOf(jsonObject.get("alarm_time") == null ? null : jsonObject.get("alarm_time").toString());
getCurAlarmDto.setAlarm_time(ts);
getCurAlarmDto.setAlarm_time(TimestampTool.string2sqlTimestamp(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());

Loading…
Cancel
Save