58 lines
1.2 KiB
Java
58 lines
1.2 KiB
Java
|
|
package com.ruoyi.device.service.convert;
|
||
|
|
|
||
|
|
import com.ruoyi.device.domain.model.Device;
|
||
|
|
import com.ruoyi.device.service.dto.DeviceDTO;
|
||
|
|
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 DeviceServiceConvert
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Model 转 DTO
|
||
|
|
*/
|
||
|
|
public static DeviceDTO toDTO(Device model)
|
||
|
|
{
|
||
|
|
if (model == null)
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
DeviceDTO dto = new DeviceDTO();
|
||
|
|
BeanUtils.copyProperties(model, dto);
|
||
|
|
return dto;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* DTO 转 Model
|
||
|
|
*/
|
||
|
|
public static Device toModel(DeviceDTO dto)
|
||
|
|
{
|
||
|
|
if (dto == null)
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
Device model = new Device();
|
||
|
|
BeanUtils.copyProperties(dto, model);
|
||
|
|
return model;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Model List 转 DTO List
|
||
|
|
*/
|
||
|
|
public static List<DeviceDTO> toDTOList(List<Device> modelList)
|
||
|
|
{
|
||
|
|
if (modelList == null)
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
return modelList.stream().map(DeviceServiceConvert::toDTO).collect(Collectors.toList());
|
||
|
|
}
|
||
|
|
}
|