tjx
2025-10-30 2ecae81fb3ab4057d367650045acc6697567c765
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.gs.xiaomi.util;
 
import com.gs.xiaomi.dto.SnListItemDto;
import com.gs.xiaomi.entity.SnListItem;
import org.springframework.beans.BeanUtils;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * SnListItem DTO和Entity转换工具类
 */
public class SnListItemConverter {
 
    /**
     * DTO转Entity
     *
     * @param dto DTO对象
     * @return Entity对象
     */
    public static SnListItem toEntity(SnListItemDto dto) {
        if (dto == null) {
            return null;
        }
        SnListItem entity = new SnListItem();
        BeanUtils.copyProperties(dto, entity);
        entity.setCreatedTime(new Date());
        entity.setUpdatedTime(new Date());
        return entity;
    }
 
    /**
     * DTO转Entity,带关联信息
     *
     * @param dto             DTO对象
     * @param deliveryMainId  送货单主表ID
     * @param zzasn           送货单号
     * @return Entity对象
     */
    public static SnListItem toEntity(SnListItemDto dto, Long deliveryMainId, String zzasn) {
        if (dto == null) {
            return null;
        }
        SnListItem entity = toEntity(dto);
        entity.setDeliveryMainId(deliveryMainId);
        entity.setZzasn(zzasn);
        return entity;
    }
 
    /**
     * Entity转DTO
     *
     * @param entity Entity对象
     * @return DTO对象
     */
    public static SnListItemDto toDto(SnListItem entity) {
        if (entity == null) {
            return null;
        }
        SnListItemDto dto = new SnListItemDto();
        BeanUtils.copyProperties(entity, dto);
        return dto;
    }
 
    /**
     * DTO列表转Entity列表
     *
     * @param dtoList DTO列表
     * @return Entity列表
     */
    public static List<SnListItem> toEntityList(List<SnListItemDto> dtoList) {
        if (dtoList == null || dtoList.isEmpty()) {
            return new ArrayList<>();
        }
        return dtoList.stream()
                .map(SnListItemConverter::toEntity)
                .collect(Collectors.toList());
    }
 
    /**
     * DTO列表转Entity列表,带关联信息
     *
     * @param dtoList         DTO列表
     * @param deliveryMainId  送货单主表ID
     * @param zzasn           送货单号
     * @return Entity列表
     */
    public static List<SnListItem> toEntityList(List<SnListItemDto> dtoList, Long deliveryMainId, String zzasn) {
        if (dtoList == null || dtoList.isEmpty()) {
            return new ArrayList<>();
        }
        return dtoList.stream()
                .map(dto -> toEntity(dto, deliveryMainId, zzasn))
                .collect(Collectors.toList());
    }
 
    /**
     * Entity列表转DTO列表
     *
     * @param entityList Entity列表
     * @return DTO列表
     */
    public static List<SnListItemDto> toDtoList(List<SnListItem> entityList) {
        if (entityList == null || entityList.isEmpty()) {
            return new ArrayList<>();
        }
        return entityList.stream()
                .map(SnListItemConverter::toDto)
                .collect(Collectors.toList());
    }
}