DashboardConverter.java
1.18 KB
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
package cn.com.glsx.app.modules.converter;
import cn.com.glsx.admin.common.util.DateUtil;
import cn.com.glsx.app.modules.model.domain.DevicePowerDO;
import cn.com.glsx.app.modules.model.view.LowPowerVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Optional;
/**
* @author xiangyanlin
* @date 2022/7/6
*/
@Mapper
public interface DashboardConverter {
DashboardConverter INSTANCE = Mappers.getMapper(DashboardConverter.class);
/**
* 转换
*
* @param source 源对象
* @return LowPowerVO
*/
@Mapping(target = "alarmTime", ignore = true)
LowPowerVO convertTo(DevicePowerDO source);
@AfterMapping
default void afterConvert(DevicePowerDO source, @MappingTarget LowPowerVO target) {
Optional.ofNullable(source.getAlarmTime())
.map(DateUtil::formatDate)
.ifPresent(target::setAlarmTime);
}
/**
* 转换
*
* @param source 源对象
* @return List<LowPowerVO>
*/
List<LowPowerVO> convertTo(List<DevicePowerDO> source);
}