Xiajijian
2025-10-11 e44aa1ce6be43c3733434426c2130d955e1024ce
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
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.SurroundModel;
import com.ard.work.component.netty.protobuf.TelemetryDataPB;
 
import java.util.List;
import java.util.stream.Collectors;
 
public class SurroundModelConverter {
    public static TelemetryDataPB.SurroundModel convertEntityToProto(SurroundModel surroundModel) {
        // 使用构建器来创建 Protobuf 对象
        TelemetryDataPB.SurroundModel.Builder builder = TelemetryDataPB.SurroundModel.newBuilder();
 
        // 复制基本属性
        builder.setServiceId(surroundModel.getServiceId());
        builder.setCameraId(surroundModel.getCameraId());
        builder.setIsModeling(surroundModel.getIsModeling());
 
        // 处理 repeated fields
        if (surroundModel.getArea() != null && !surroundModel.getArea().isEmpty()) {
            List<TelemetryDataPB.PointData> area = surroundModel.getArea().stream()
                    .map(PointDataConverter::convertEntityToProto)
                    .collect(Collectors.toList());
            builder.addAllArea(area);
        }
 
        // 构建并返回 Protobuf 对象
        return builder.build();
    }
 
    public static SurroundModel convertProtoToEntity(TelemetryDataPB.SurroundModel proto) {
        SurroundModel surroundModel = new SurroundModel();
        BeanUtils.copyProperties(proto, surroundModel);
 
        // 处理 repeated fields
        if (proto.getAreaCount() > 0) {
            List<PointData> area = proto.getAreaList().stream()
                    .map(PointDataConverter::convertProtoToEntity)
                    .collect(Collectors.toList());
            surroundModel.setArea(area);
        }
        
        return surroundModel;
    }
}