All Downloads are FREE. Search and download functionalities are using the official Maven repository.

icu.mhb.mybatisplus.plugln.tookit.MappingUtil Maven / Gradle / Ivy

There is a newer version: 1.3.8
Show newest version
package icu.mhb.mybatisplus.plugln.tookit;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import icu.mhb.mybatisplus.plugln.core.JoinLambdaWrapper;
import icu.mhb.mybatisplus.plugln.entity.OneToOneSelectBuild;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mahuibo
 * @Title: MappingUtil
 * @email [email protected]
 * @time 2021/12/17
 */
public class MappingUtil {

    /**
     * 对传入的map进行一对一的映射
     *
     * @param maps                 结果映射
     * @param oneToOneSelectBuilds 一对一映射配置
     * @return 映射后的map
     */
    public static void oneToOneMapping(List> maps, List oneToOneSelectBuilds) {

        for (OneToOneSelectBuild oneSelectBuild : oneToOneSelectBuilds) {
            for (Map map : maps) {
                Map oneToOneMap = new HashMap<>();

                // 提取map中对应的一对一对应的值
                oneSelectBuild.getBelongsColumns()
                        .forEach((fieldMapping) -> MapUtil.notNullPut(StringUtils.isNotEmpty(fieldMapping.getFieldName()) ? fieldMapping.getFieldName() : fieldMapping.getColumn(), MapUtil.getAndRemove(fieldMapping.getColumn(), map), oneToOneMap));

                map.put(oneSelectBuild.getOneToOneField(), oneToOneMap);
            }
        }
    }

    public static  void wrapperOneToOneMapping(List> objectMap, JoinLambdaWrapper wrapper) {
        List oneToOneSelectBuildList = wrapper.getOneToOneSelectBuildList();
        // 如果不为空就代表有一对一配置
        if (CollectionUtils.isNotEmpty(oneToOneSelectBuildList)) {
            oneToOneMapping(objectMap, oneToOneSelectBuildList);
        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy