liusuyi
2025-11-25 f789cb13684b73ad38c7a6b1720e49500cfec822
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.ard.work.domain.dto.converter.wayline;
 
import com.ard.common.utils.bean.BeanUtils;
import com.ard.work.domain.dto.state.PointData;
import com.ard.work.domain.dto.wayline.PointAction;
import com.ard.work.component.netty.protobuf.TelemetryDataPB;
 
import java.util.List;
import java.util.stream.Collectors;
 
public class PointDataConverter {
    public static TelemetryDataPB.PointData convertEntityToProto(PointData pointData) {
        // 使用构建器来创建 Protobuf 对象
        TelemetryDataPB.PointData.Builder builder = TelemetryDataPB.PointData.newBuilder();
 
        // 复制基本属性
        builder.setLng(pointData.getLng());
        builder.setLat(pointData.getLat());
        builder.setHeight(pointData.getHeight());
        builder.setSpeed(pointData.getSpeed());
        builder.setFlightPathMode(pointData.getFlightPathMode());
        builder.setDampingDistance(pointData.getDampingDistance());
        builder.setSafeGohomeFlag(pointData.getSafeGohomeFlag());
        builder.setHeadingMode(pointData.getHeadingMode());
        builder.setHeading(pointData.getHeading());
        builder.setInterestIndex(pointData.getInterestIndex());
        builder.setGroupIndex(pointData.getGroupIndex());
 
        // 处理动作数组
        if (pointData.getActions() != null && !pointData.getActions().isEmpty()) {
            List<TelemetryDataPB.PointAction> actions = pointData.getActions().stream()
                    .map(PointActionConverter::convertEntityToProto)
                    .collect(Collectors.toList());
            builder.addAllActions(actions);
        }
 
        // 构建并返回 Protobuf 对象
        return builder.build();
    }
 
    public static PointData convertProtoToEntity(TelemetryDataPB.PointData proto) {
        PointData pointData = new PointData();
        BeanUtils.copyProperties(proto, pointData);
        // 处理 repeated fields
        if (proto.getActionsCount() > 0) {
            List<PointAction> actions = proto.getActionsList().stream()
                    .map(PointActionConverter::convertProtoToEntity)
                    .collect(Collectors.toList());
            pointData.setActions(actions);
        }
        return pointData;
    }
}