58 lines
1.2 KiB
Java
58 lines
1.2 KiB
Java
package com.ruoyi.device.service.convert;
|
|
|
|
import com.ruoyi.device.domain.model.Payload;
|
|
import com.ruoyi.device.service.dto.PayloadDTO;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 挂载Service层转换器
|
|
* Service DTO ↔ Domain Model
|
|
*
|
|
* @author ruoyi
|
|
* @date 2026-01-16
|
|
*/
|
|
public class PayloadServiceConvert
|
|
{
|
|
/**
|
|
* Model 转 DTO
|
|
*/
|
|
public static PayloadDTO toDTO(Payload model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
PayloadDTO dto = new PayloadDTO();
|
|
BeanUtils.copyProperties(model, dto);
|
|
return dto;
|
|
}
|
|
|
|
/**
|
|
* DTO 转 Model
|
|
*/
|
|
public static Payload toModel(PayloadDTO dto)
|
|
{
|
|
if (dto == null)
|
|
{
|
|
return null;
|
|
}
|
|
Payload model = new Payload();
|
|
BeanUtils.copyProperties(dto, model);
|
|
return model;
|
|
}
|
|
|
|
/**
|
|
* Model List 转 DTO List
|
|
*/
|
|
public static List<PayloadDTO> toDTOList(List<Payload> modelList)
|
|
{
|
|
if (modelList == null)
|
|
{
|
|
return null;
|
|
}
|
|
return modelList.stream().map(PayloadServiceConvert::toDTO).collect(Collectors.toList());
|
|
}
|
|
} |