Commit be6a49ce by s_guodong

增加从根节点获取值

parent 27862d52
...@@ -6,6 +6,8 @@ import com.brilliance.mda.runtime.mda.snapshot.bo.unpack.*; ...@@ -6,6 +6,8 @@ import com.brilliance.mda.runtime.mda.snapshot.bo.unpack.*;
import com.brilliance.mda.runtime.mda.util.MdaUtils; import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.mda.util.XmlUtil; import com.brilliance.mda.runtime.mda.util.XmlUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
...@@ -21,6 +23,8 @@ import java.util.*; ...@@ -21,6 +23,8 @@ import java.util.*;
*/ */
@Service @Service
public class SnapshotServiceImpl implements SnapshotService { public class SnapshotServiceImpl implements SnapshotService {
private static Logger log = LoggerFactory.getLogger(SnapshotServiceImpl.class);
protected static final String DISPLAY_TEMPLATE_PATH = "displayTemplate/"; protected static final String DISPLAY_TEMPLATE_PATH = "displayTemplate/";
private static final Set<String> keySet = new HashSet<>(); private static final Set<String> keySet = new HashSet<>();
...@@ -116,13 +120,19 @@ public class SnapshotServiceImpl implements SnapshotService { ...@@ -116,13 +120,19 @@ public class SnapshotServiceImpl implements SnapshotService {
} }
for (LabelBo labelBo : labelList) { for (LabelBo labelBo : labelList) {
PackLabelBo data = new PackLabelBo();
CustomAttributes customAttributes = labelBo.getCustomAttributes(); CustomAttributes customAttributes = labelBo.getCustomAttributes();
String value = customAttributes.getLabelId(); String value = customAttributes.getLabelId();
PackLabelBo data = new PackLabelBo(); if (StringUtils.isBlank(value)) {
// /bctp/LT000070/ value = customAttributes.getFieldUrl();
String[] split = value.substring(1, value.length() - 1).split("/"); keySet.add(value);
String i18NString = MdaUtils.getI18NString(split[0], split[1]); data.setValue("${" + value + "}");
data.setValue(i18NString); } else {
// /bctp/LT000070/
String[] split = value.substring(1, value.length() - 1).split("/");
String i18NString = MdaUtils.getI18NString(split[0], split[1]);
data.setValue(i18NString);
}
data.setStyle(labelBo.getStyle()); data.setStyle(labelBo.getStyle());
labelBoList.add(data); labelBoList.add(data);
} }
...@@ -198,26 +208,65 @@ public class SnapshotServiceImpl implements SnapshotService { ...@@ -198,26 +208,65 @@ public class SnapshotServiceImpl implements SnapshotService {
@Override @Override
public Map<String, Object> getValueMap(Set<String> keySet, IModule parent) { public Map<String, Object> getValueMap(Set<String> keySet, IModule parent) {
Map<String, Object> valueMap = new HashMap(); Map<String, Object> valueMap = new HashMap();
IModule root = getRoot(parent);
for (String key : keySet) { for (String key : keySet) {
String[] split = key.split("\\\\"); if (key.startsWith("\\")) {
Class aClass = parent.getClass(); // 从根节点获取值
Object value = ""; getValueFromModule(valueMap, root, key);
Object obj = parent; } else {
for (int i = 0; i < split.length; i++) { getValueFromModule(valueMap, parent, key);
String s = split[i];
try {
Method getMethod = aClass.getDeclaredMethod("get" + s.substring(0, 1).toUpperCase() + s.substring(1));
value = getMethod.invoke(obj);
aClass = value.getClass();
obj = value;
} catch (Exception e) {
}
} }
valueMap.put(key, value == null ? "" : value);
} }
return valueMap; return valueMap;
} }
/**
* 获取根节点
*
* @param module
* @return
*/
private IModule getRoot(IModule module) {
IModule parent = module.getParent();
if (parent == null) {
return module;
}
return getRoot(parent);
}
/**
* 从模型中取值
*
* @param valueMap
* @param parent
* @param key
*/
private void getValueFromModule(Map<String, Object> valueMap, IModule parent, String key) {
String originKey = key;
if (key.startsWith("\\")) {
key = key.substring(1);
}
String[] split = key.split("\\\\");
Class aClass = parent.getClass();
Object value = "";
Object obj = parent;
for (int i = 0; i < split.length; i++) {
String s = split[i];
try {
Method getMethod = aClass.getDeclaredMethod("get" + s.substring(0, 1).toUpperCase() + s.substring(1));
value = getMethod.invoke(obj);
if (value == null) {
break;
}
aClass = value.getClass();
obj = value;
} catch (Exception e) {
log.error("获取模板中的值{}错误:", originKey, e);
}
}
valueMap.put(originKey, value == null ? "" : value);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment