package com.zhitan.util;
|
|
import com.zhitan.model.entity.DeviceData;
|
import com.zhitan.model.entity.KtDataEntity;
|
|
public class KtDataMapper {
|
public static KtDataEntity mapToEntity(DeviceData deviceData)
|
{
|
KtDataEntity ktDataEntity = new KtDataEntity();
|
ktDataEntity.setSn(deviceData.getParams().getSysSn());
|
ktDataEntity.setImei(deviceData.getParams().getSysImei());
|
ktDataEntity.setTime(deviceData.getParams().getSysTime());
|
deviceData.getParams().getRData().forEach(item -> {
|
if ("tmp".equals(item.getName())) {
|
ktDataEntity.setTmp(parseDouble(item.getValue()));
|
} else if ("hum".equals(item.getName())) {
|
ktDataEntity.setHum(parseDouble(item.getValue()));
|
} else if ("I".equals(item.getName())) {
|
ktDataEntity.setIa(parseDouble(item.getValue()));
|
}
|
});
|
return ktDataEntity;
|
}
|
|
private static Double parseDouble(String s) {
|
return s != null ? Double.parseDouble(s) : null;
|
}
|
}
|