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

com.gitee.qdbp.filling.biz.BaseEntityDataFillGroupValueService Maven / Gradle / Ivy

package com.gitee.qdbp.filling.biz;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.gitee.qdbp.able.beans.KeyString;
import com.gitee.qdbp.tools.utils.VerifyTools;

/**
 * 实体数据分组填充单一类型处理基础实现类
* options多个字段以逗号分隔, 默认的填充字段为源字段去掉Id/Code后缀, 加上Name
* -- createUser,updateUser
* -- 等于createUser-createUserName,updateUser-updateUserName
* 也可以自定义转换关系
* -- creatorId-createUser,updatorId-updateUser
* * @author zhaohuihua * @version 20210113 */ public abstract class BaseEntityDataFillGroupValueService extends BaseEntityDataFillFieldValueBasic { /** 获取分组类型 **/ protected T getTargetGroupType(Map data) { return null; } /** 查找目标值 (key=sourceValue, value=targetValue) **/ protected abstract Map findTargetValueMaps(T groupType, Collection sourceValues); @Override public void fillFieldValue(Iterable> list, String option) { List options = parseOptions(option); // 分组 Map>> groups = new HashMap<>(); List> defaultGroups = new ArrayList<>(); for (Map item : list) { T groupType = getTargetGroupType(item); if (VerifyTools.isBlank(groupType)) { defaultGroups.add(item); } else { if (groups.containsKey(groupType)) { groups.get(groupType).add(item); } else { List> items = new ArrayList<>(); items.add(item); groups.put(groupType, items); } } } for (Map.Entry>> entry : groups.entrySet()) { fillFieldValue(entry.getKey(), entry.getValue(), options); } if (!defaultGroups.isEmpty()) { fillFieldValue(null, defaultGroups, options); } } protected void fillFieldValue(T groupType, Iterable> list, List options) { // # 收集需要填充的信息 // key=sourceValue Map> sourceMaps = collectFillInfos(list, options); if (sourceMaps == null || sourceMaps.isEmpty()) { return; } // # 根据sourceValue查询targetValue List sourceValues = new ArrayList<>(sourceMaps.keySet()); // 复制副本以防修改 // key=sourceValue, value=targetValue Map targetMaps = findTargetValueMaps(groupType, sourceValues); if (targetMaps == null || targetMaps.isEmpty()) { return; } // # 将targetValue填充至originalData fillValueToOriginalData(sourceMaps, targetMaps); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy