baoshiwei
2025-06-19 be00ddc83f86599916eb8d0f581f448aa74c9d51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
    }
}