package com.gs.xiaomi.util;
|
|
import com.gs.xiaomi.dto.CartonListItemDto;
|
import com.gs.xiaomi.entity.CartonListItem;
|
import org.springframework.beans.BeanUtils;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* CartonListItem DTO和Entity转换工具类
|
*/
|
public class CartonListItemConverter {
|
|
/**
|
* DTO转Entity
|
*
|
* @param dto DTO对象
|
* @return Entity对象
|
*/
|
public static CartonListItem toEntity(CartonListItemDto dto) {
|
if (dto == null) {
|
return null;
|
}
|
CartonListItem entity = new CartonListItem();
|
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 CartonListItem toEntity(CartonListItemDto dto, Long deliveryMainId, String zzasn) {
|
if (dto == null) {
|
return null;
|
}
|
CartonListItem entity = toEntity(dto);
|
entity.setDeliveryMainId(deliveryMainId);
|
entity.setZzasn(zzasn);
|
return entity;
|
}
|
|
/**
|
* Entity转DTO
|
*
|
* @param entity Entity对象
|
* @return DTO对象
|
*/
|
public static CartonListItemDto toDto(CartonListItem entity) {
|
if (entity == null) {
|
return null;
|
}
|
CartonListItemDto dto = new CartonListItemDto();
|
BeanUtils.copyProperties(entity, dto);
|
return dto;
|
}
|
|
/**
|
* DTO列表转Entity列表
|
*
|
* @param dtoList DTO列表
|
* @return Entity列表
|
*/
|
public static List<CartonListItem> toEntityList(List<CartonListItemDto> dtoList) {
|
if (dtoList == null || dtoList.isEmpty()) {
|
return new ArrayList<>();
|
}
|
return dtoList.stream()
|
.map(CartonListItemConverter::toEntity)
|
.collect(Collectors.toList());
|
}
|
|
/**
|
* DTO列表转Entity列表,带关联信息
|
*
|
* @param dtoList DTO列表
|
* @param deliveryMainId 送货单主表ID
|
* @param zzasn 送货单号
|
* @return Entity列表
|
*/
|
public static List<CartonListItem> toEntityList(List<CartonListItemDto> 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<CartonListItemDto> toDtoList(List<CartonListItem> entityList) {
|
if (entityList == null || entityList.isEmpty()) {
|
return new ArrayList<>();
|
}
|
return entityList.stream()
|
.map(CartonListItemConverter::toDto)
|
.collect(Collectors.toList());
|
}
|
}
|