package com.shkj.wms.utils;

import org.dozer.DozerBeanMapperBuilder;
import org.dozer.Mapper;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 转化实体
 *
 * @author lch
 */
public class BeanMapperUtils {

    private static Mapper MAPPER = DozerBeanMapperBuilder.buildDefault();

    public static <T> T map(Object source, Class<T> destinationClass) {
        if (source == null) {
            return null;
        }
        return MAPPER.map(source, destinationClass);
    }

    public static void map(Object source, Object destination) {
        if (source == null) {
            destination = null;
            return;
        }
        MAPPER.map(source, destination);
    }

    public static <T> List<T> mapList(Collection sourceList, Class<T> destinationClass) {
        List<T> destinationList = new ArrayList<>();
        for (Object sourceObject : sourceList) {
            destinationList.add(MAPPER.map(sourceObject, destinationClass));
        }
        return destinationList;
    }

//    /**
//     * page 转化
//     *
//     * @param pageResult
//     * @param tList
//     * @param <T>
//     * @return
//     */
//    public static <T> PageInfo<T> pageConvert(PageInfo pageResult, List<T> tList) {
//        PageInfo<T> tPageResult = new PageInfo<>();
//        map(pageResult, tPageResult);
//        tPageResult.setList(tList);
//        return tPageResult;
//    }


}
