|
@@ -1,6 +1,7 @@
|
|
|
package com.lantone.qc.trans.beilun.util.ez.util;
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
+import com.lantone.qc.dbanaly.facade.yiwu.util.MapUtil;
|
|
|
import com.lantone.qc.pub.util.StringUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dom4j.Attribute;
|
|
@@ -9,8 +10,10 @@ import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.Element;
|
|
|
import org.dom4j.Node;
|
|
|
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @Description:
|
|
@@ -101,4 +104,44 @@ public class EzXmlUtil {
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据给定key映射
|
|
|
+ *
|
|
|
+ * @param sourceMap
|
|
|
+ * @param keyContrasts
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Map<String, String> mapKeyContrast(Map<String, String> sourceMap, List<String> keyContrasts) {
|
|
|
+ Map<String, String> retMap = Maps.newHashMap();
|
|
|
+ mapKeyContrastCommon(sourceMap, keyContrasts, retMap);
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void mapKeyContrastCommon(Map sourceMap, List<String> keyContrasts, Map<String, String> retMap) {
|
|
|
+ Map<String, String> sourceMap_ = MapUtil.copyMap(sourceMap);
|
|
|
+ String[] arry = null;
|
|
|
+ String sourceKey = null, targetKey;
|
|
|
+ Set<String> removeKey = new HashSet<>();
|
|
|
+ for (String keyContrast : keyContrasts) {
|
|
|
+ arry = keyContrast.split("=");
|
|
|
+ sourceKey = arry[0];
|
|
|
+ if (arry.length == 1) {
|
|
|
+ targetKey = arry[0];
|
|
|
+ } else {
|
|
|
+ targetKey = arry[1];
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(sourceMap_.get(sourceKey))
|
|
|
+ && (!retMap.containsKey(targetKey) || StringUtil.isBlank(retMap.get(targetKey)))) {
|
|
|
+ retMap.put(targetKey, sourceMap_.get(sourceKey));
|
|
|
+ }
|
|
|
+ removeKey.add(sourceKey);
|
|
|
+ }
|
|
|
+ Set<String> keySet = retMap.keySet();
|
|
|
+ for (String key : sourceMap_.keySet()) {
|
|
|
+ if (!keySet.contains(key) && !removeKey.contains(key)) { // 如果之前已放过key就不用放了
|
|
|
+ retMap.put(key, sourceMap_.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|