Commit be6a49ce by s_guodong

增加从根节点获取值

parent 27862d52
......@@ -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.XmlUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.io.File;
......@@ -21,6 +23,8 @@ import java.util.*;
*/
@Service
public class SnapshotServiceImpl implements SnapshotService {
private static Logger log = LoggerFactory.getLogger(SnapshotServiceImpl.class);
protected static final String DISPLAY_TEMPLATE_PATH = "displayTemplate/";
private static final Set<String> keySet = new HashSet<>();
......@@ -116,13 +120,19 @@ public class SnapshotServiceImpl implements SnapshotService {
}
for (LabelBo labelBo : labelList) {
PackLabelBo data = new PackLabelBo();
CustomAttributes customAttributes = labelBo.getCustomAttributes();
String value = customAttributes.getLabelId();
PackLabelBo data = new PackLabelBo();
// /bctp/LT000070/
String[] split = value.substring(1, value.length() - 1).split("/");
String i18NString = MdaUtils.getI18NString(split[0], split[1]);
data.setValue(i18NString);
if (StringUtils.isBlank(value)) {
value = customAttributes.getFieldUrl();
keySet.add(value);
data.setValue("${" + value + "}");
} 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());
labelBoList.add(data);
}
......@@ -198,26 +208,65 @@ public class SnapshotServiceImpl implements SnapshotService {
@Override
public Map<String, Object> getValueMap(Set<String> keySet, IModule parent) {
Map<String, Object> valueMap = new HashMap();
IModule root = getRoot(parent);
for (String key : keySet) {
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);
aClass = value.getClass();
obj = value;
} catch (Exception e) {
}
if (key.startsWith("\\")) {
// 从根节点获取值
getValueFromModule(valueMap, root, key);
} else {
getValueFromModule(valueMap, parent, key);
}
valueMap.put(key, value == null ? "" : value);
}
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