Commit b4221c36 by s_guodong

快照中列表的渲染

parent 6887dadd
package com.brilliance.test;
import com.brilliance.mda.runtime.mda.snapshot.SnapshotServiceImpl;
import java.util.HashSet;
public class Test {
......@@ -16,11 +14,5 @@ public class Test {
System.out.println(set);
}
@org.junit.jupiter.api.Test
public void getTemplateContent() {
SnapshotServiceImpl snapshotServiceImpl = new SnapshotServiceImpl();
String templateContent = snapshotServiceImpl.getTemplateContent("litp.nlitp");
System.out.println(templateContent);
}
}
......@@ -259,7 +259,7 @@ public class MdaContext implements IContext {
IModule parent = panel.getParent();
String panelPath = panel.getPath();
// 获取模板内容
String templateContent = snapshotService.getTemplateContent(panelPath);
String templateContent = snapshotService.getTemplateContent(panelPath,parent);
// 获取填充值的key
Set<ValueVo> keySet = snapshotService.getKeySet();
// 获取填充的值
......
......@@ -18,9 +18,10 @@ public interface SnapshotService {
* 获取模板内容
*
* @param panelPath
* @param parent
* @return
*/
String getTemplateContent(String panelPath);
String getTemplateContent(String panelPath, IModule parent);
/**
* 获取快照模板中所需的值
......@@ -43,9 +44,10 @@ public interface SnapshotService {
* 组装成xml需要的实体
*
* @param documentBo
* @param parent
* @return
*/
PackDocumentBo packTemplate(DocumentBo documentBo);
PackDocumentBo packTemplate(DocumentBo documentBo, IModule parent);
/**
* 获取需要填充值的实体
......
package com.brilliance.mda.runtime.mda.snapshot;
import com.brilliance.mda.runtime.mda.IModule;
import com.brilliance.mda.runtime.mda.impl.ModuleList;
import com.brilliance.mda.runtime.mda.snapshot.bo.ValueVo;
import com.brilliance.mda.runtime.mda.snapshot.bo.pack.*;
import com.brilliance.mda.runtime.mda.snapshot.bo.unpack.*;
import com.brilliance.mda.runtime.mda.util.DateUtil;
import com.brilliance.mda.runtime.mda.util.DateUtils;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.mda.util.XmlUtil;
import org.apache.commons.lang3.StringUtils;
......@@ -32,11 +33,11 @@ public class SnapshotServiceImpl implements SnapshotService {
private static final Set<ValueVo> keySet = new HashSet<>();
@Override
public String getTemplateContent(String panelPath) {
public String getTemplateContent(String panelPath, IModule parent) {
// 解析标准模板
DocumentBo documentBo = this.unpackTemplate(panelPath);
// 获取组装xml的实体
PackDocumentBo packDocumentBo = this.packTemplate(documentBo);
PackDocumentBo packDocumentBo = this.packTemplate(documentBo, parent);
String s = XmlUtil.marshToXmlBinding(PackDocumentBo.class, packDocumentBo);
String replace = s.replace("<window>", "<window xmlns=\"http://www.zkoss.org/2005/zul\" xmlns:w=\"http://www.zkoss.org/2005/zk/client\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" height=\"100%\" width=\"100%\" xsi:schemaLocation=\"http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd\">");
return replace;
......@@ -63,7 +64,7 @@ public class SnapshotServiceImpl implements SnapshotService {
@Override
public PackDocumentBo packTemplate(DocumentBo documentBo) {
public PackDocumentBo packTemplate(DocumentBo documentBo, IModule parent) {
keySet.clear();
List<TextboxBo> textboxList;
......@@ -114,7 +115,7 @@ public class SnapshotServiceImpl implements SnapshotService {
packDivBo.setCheckboxBoList(handleCheckboxList(checkboxList));
// listboxList
packDivBo.setListboxBoList(handleListboxList(listboxList));
packDivBo.setListboxBoList(handleListboxList(listboxList, parent));
// 组成xml需要的实体
PackBorderlayoutBo packBorderlayoutBo = new PackBorderlayoutBo();
......@@ -193,26 +194,11 @@ public class SnapshotServiceImpl implements SnapshotService {
aClass = value.getClass();
obj = value;
} catch (Exception e) {
log.error("获取模板中的值{}错误:", originKey, e);
}
}
if (value != null) {
String format = valueVo.getFormat();
String codeTable = valueVo.getCodeTable();
// 从码表中转换
if (StringUtils.isNotBlank(codeTable)) {
value = MdaUtils.getCodetableLabel(codeTable, (String) value);
}
// 时间格式化
if (StringUtils.isNotBlank(format) && value instanceof Date) {
value = DateUtil.format((Date) value, format.replaceAll("/", "-"));
}
// boolean 类型转换为String
if (value instanceof Boolean) {
value = String.valueOf(value);
log.warn("获取模板中的值{}为空", originKey);
}
}
// 格式转换
value = formatValue(value, valueVo);
valueMap.put(originKey, value == null ? "" : value);
}
......@@ -260,11 +246,13 @@ public class SnapshotServiceImpl implements SnapshotService {
for (TextboxBo textboxBo : textboxList) {
List<CustomAttributes> customAttributes = textboxBo.getCustomAttributes();
String text = getAttributeValue(customAttributes).getFieldUrl();
PackTextboxBo data = new PackTextboxBo();
if (StringUtils.isNotBlank(text)) {
keySet.add(new ValueVo(text));
data.setText("${" + text + "}");
} else {
data.setText("");
}
PackTextboxBo data = new PackTextboxBo();
data.setText("${" + text + "}");
data.setStyle(textboxBo.getStyle());
data.setCols(textboxBo.getCols());
data.setRows(textboxBo.getRows() == null ? "1" : textboxBo.getRows());
......@@ -323,12 +311,13 @@ public class SnapshotServiceImpl implements SnapshotService {
CustomAttributes attributeValue = getAttributeValue(customAttributes);
String text = attributeValue.getFieldUrl();
PackComboboxBo data = new PackComboboxBo();
if (StringUtils.isNotBlank(text)) {
keySet.add(new ValueVo(text, null, attributeValue.getCodeTable()));
data.setText("${" + text + "}");
} else {
data.setText("");
}
PackComboboxBo data = new PackComboboxBo();
data.setText("${" + text + "}");
data.setStyle(textboxBo.getStyle());
comboboxBoList.add(data);
}
......@@ -350,11 +339,13 @@ public class SnapshotServiceImpl implements SnapshotService {
for (TextboxBo textboxBo : xdateboxList) {
List<CustomAttributes> customAttributes = textboxBo.getCustomAttributes();
String text = getAttributeValue(customAttributes).getFieldUrl();
PackDateboxBo data = new PackDateboxBo();
if (StringUtils.isNotBlank(text)) {
keySet.add(new ValueVo(text, textboxBo.getFormat(), null));
data.setText("${" + text + "}");
} else {
data.setText("");
}
PackDateboxBo data = new PackDateboxBo();
data.setText("${" + text + "}");
data.setStyle(textboxBo.getStyle());
data.setFormat(textboxBo.getFormat());
dateboxBoList.add(data);
......@@ -377,11 +368,13 @@ public class SnapshotServiceImpl implements SnapshotService {
for (TextboxBo textboxBo : xdecimalboxList) {
List<CustomAttributes> customAttributes = textboxBo.getCustomAttributes();
String text = getAttributeValue(customAttributes).getFieldUrl();
PackDecimalboxBo data = new PackDecimalboxBo();
if (StringUtils.isNotBlank(text)) {
keySet.add(new ValueVo(text));
data.setText("${" + text + "}");
} else {
data.setText("");
}
PackDecimalboxBo data = new PackDecimalboxBo();
data.setText("${" + text + "}");
data.setStyle(textboxBo.getStyle());
data.setFormat(textboxBo.getFormat());
decimalboxBoList.add(data);
......@@ -408,16 +401,22 @@ public class SnapshotServiceImpl implements SnapshotService {
String labelId = attributeValue.getLabelId();
if (StringUtils.isBlank(labelId)) {
labelId = attributeValue.getFieldUrl();
keySet.add(new ValueVo(labelId));
data.setLabel("${" + labelId + "}");
// labelId = attributeValue.getFieldUrl();
data.setLabel("${" + fieldUrl + "}");
keySet.add(new ValueVo(fieldUrl));
} else {
// /bctp/LT000070/
String[] split = labelId.substring(1, labelId.length() - 1).split("/");
String i18NString = MdaUtils.getI18NString(split[0], split[1]);
data.setLabel(i18NString);
}
data.setChecked("${" + fieldUrl + "}");
if (StringUtils.isNotBlank(fieldUrl)) {
data.setChecked("${" + fieldUrl + "}");
keySet.add(new ValueVo(fieldUrl));
} else {
data.setChecked("");
}
data.setStyle(checkboxBo.getStyle());
checkboxBoList.add(data);
}
......@@ -429,9 +428,10 @@ public class SnapshotServiceImpl implements SnapshotService {
* 处理listboxList
*
* @param listboxList
* @param parent
* @return
*/
private List<PackListboxBo> handleListboxList(List<ListboxBo> listboxList) {
private List<PackListboxBo> handleListboxList(List<ListboxBo> listboxList, IModule parent) {
List<PackListboxBo> listboxBoList = new ArrayList<>();
if (listboxList == null) {
return listboxBoList;
......@@ -441,16 +441,12 @@ public class SnapshotServiceImpl implements SnapshotService {
// 表头
PackListheadBo packListhead = new PackListheadBo();
List<PackListheaderBo> listheader = new ArrayList<>();
// 表数据
PackListitemBo packListiteam = new PackListitemBo();
List<PackListcellBo> listcell = new ArrayList<>();
ListheadBo listhead = listbox.getListhead();
CustomAttributes attributeValue = getAttributeValue(listbox.getCustomAttributes());
String fieldUrl = attributeValue.getFieldUrl();
String rowHeight = attributeValue.getRowHeight();
Set<String> columnNameSet = new HashSet<>();
List<CustomAttributes> customAttributesList = new ArrayList<>();
List<ListheaderBo> listheaderList = listhead.getListheaderList();
for (ListheaderBo listheaderBo : listheaderList) {
List<CustomAttributes> customAttributes = listheaderBo.getCustomAttributes();
......@@ -465,10 +461,35 @@ public class SnapshotServiceImpl implements SnapshotService {
listheaderData.setLabel(i18NString);
listheaderData.setStyle(listheaderBo.getStyle());
listheader.add(listheaderData);
// 表格字段名
columnNameSet.add(attributeValue1.getColumnName());
// 表格字段属性
customAttributesList.add(attributeValue1);
}
// 表数据
List<PackListitemBo> packListiteam = new ArrayList<>();
String fieldUrl = attributeValue.getFieldUrl();
String rowHeight = attributeValue.getRowHeight();
List<Map<String, Object>> value4List = getValue4List(fieldUrl, parent, columnNameSet);
for (Map<String, Object> map : value4List) {
List<PackListcellBo> listcell = new ArrayList<>();
for (CustomAttributes customAttributes : customAttributesList) {
Object value = map.get(customAttributes.getColumnName());
// 格式转换
value = formatValue(value, new ValueVo(null, customAttributes.getFormatter(), customAttributes.getCodeTable()));
PackListcellBo listCellData = new PackListcellBo();
listCellData.setLabel(value == null ? "" : String.valueOf(value));
listCellData.setStyle(customAttributes.getColumnStyle());
listcell.add(listCellData);
}
PackListitemBo packListitemBo = new PackListitemBo();
packListitemBo.setListcell(listcell);
packListitemBo.setHeight(rowHeight);
packListiteam.add(packListitemBo);
}
packListiteam.setListcell(listcell);
packListiteam.setHeight(rowHeight);
packListhead.setListheader(listheader);
data.setPackListheadBo(packListhead);
data.setPackListitemBo(packListiteam);
......@@ -479,4 +500,69 @@ public class SnapshotServiceImpl implements SnapshotService {
}
/**
* 获取列表中的值
*
* @param fieldUrl
* @param parent
* @param columnNameSet
* @return
*/
private List<Map<String, Object>> getValue4List(String fieldUrl, IModule parent, Set<String> columnNameSet) {
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> valueMap = new HashMap();
IModule root = getRoot(parent);
if (fieldUrl.startsWith("\\")) {
// 从根节点获取值
getValueFromModule(valueMap, root, new ValueVo(fieldUrl));
} else {
getValueFromModule(valueMap, parent, new ValueVo(fieldUrl));
}
ModuleList moduleList = (ModuleList) valueMap.get(fieldUrl);
for (int i = 0; i < moduleList.fullSize(); i++) {
Map<String, Object> data = new HashMap<>();
IModule module = moduleList.getElement(i);
Class<? extends IModule> aClass = module.getClass();
for (String columnName : columnNameSet) {
try {
Method getMethod = aClass.getDeclaredMethod("get" + columnName.substring(0, 1).toUpperCase() + columnName.substring(1));
Object value = getMethod.invoke(module);
data.put(columnName, value);
} catch (Exception e) {
}
}
list.add(data);
}
return list;
}
/**
* 格式转换
*
* @param value
* @param valueVo
* @return
*/
private Object formatValue(Object value, ValueVo valueVo) {
if (value != null) {
String format = valueVo.getFormat();
String codeTable = valueVo.getCodeTable();
// 从码表中转换
if (StringUtils.isNotBlank(codeTable)) {
value = MdaUtils.getCodetableLabel(codeTable, (String) value);
}
// 时间格式化
if (StringUtils.isNotBlank(format) && value instanceof Date) {
value = DateUtils.format((Date) value, format.replaceAll("/", "-"));
}
// boolean 类型转换为String
if (value instanceof Boolean) {
value = String.valueOf(value);
}
}
return value;
}
}
......@@ -3,6 +3,7 @@ package com.brilliance.mda.runtime.mda.snapshot.bo.pack;
import lombok.Data;
import javax.xml.bind.annotation.*;
import java.util.List;
/**
* @Description
......@@ -23,5 +24,5 @@ public class PackListboxBo {
private PackListheadBo packListheadBo;
@XmlElement(name = "listitem")
private PackListitemBo packListitemBo;
private List<PackListitemBo> packListitemBo;
}
......@@ -9,7 +9,7 @@ import java.util.Date;
* @Author s_guodong
* @Date 2023/8/21
*/
public class DateUtil {
public class DateUtils {
public static String format(Date date, String pattern) {
DateFormat dateFormat = new SimpleDateFormat(pattern);
......
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