ludc
2023-04-26 3cb0cef6f7189dcbb537df52cef5921d1d2c3cd9
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
package com.vci.ubcs.omd.wrapper;
 
import com.vci.ubcs.omd.entity.Attribute;
import com.vci.ubcs.omd.vo.*;
import com.vci.ubcs.system.cache.DictBizCache;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.StringUtil;
 
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
 
/**
 * 元数据对象的包装类,返回视图层所需的字段
 *
 * @author LiHang
 * @date 2023/4/3
 */
public class AttributeWrapper extends BaseEntityWrapper<Attribute, AttributeVO> {
 
    public static AttributeWrapper build() {
        return new AttributeWrapper();
    }
 
    /**
     * do2vo
     * @param entity pojo
     * @return 显示对象
     */
    @Override
    public AttributeVO entityVO(Attribute entity) {
        AttributeVO vo = Objects.requireNonNull(BeanUtil.copy(entity, AttributeVO.class));
        vo.setTypeValue(DictBizCache.getValue(vo.getTypeCode(),vo.getTypeKey()));
        if (StringUtil.isNotBlank(vo.getReferTypeCode())){
            vo.setReferTypeValue(DictBizCache.getValue(vo.getReferTypeCode(),vo.getReferTypeKey()));
        }
        if (StringUtil.isNotBlank(vo.getDictCode())){
            vo.setDictValue(DictBizCache.getValue(vo.getDictCode(),vo.getDictKey()));
        }
        return vo;
    }
 
    /**
     * 批量转vo
     * @param list pojo集合
     * @return 显示对象
     */
    public List<AttributeVO> listEntityVO(List<Attribute> list) {
        return list.stream().map(this::entityVO).collect(Collectors.toList());
    }
}