Commit 20cce451 by s_guodong

动态码表

parent 010bb492
package com.brilliance.mda.runtime.mda.snapshot;
import com.brilliance.mda.runtime.mda.CodetableItem;
import com.brilliance.mda.runtime.mda.Constants;
import com.brilliance.mda.runtime.mda.IModule;
import com.brilliance.mda.runtime.mda.IPanel;
......@@ -197,7 +198,7 @@ public class SnapshotServiceImpl implements SnapshotService {
}
}
// 格式转换
value = formatValue(value, valueVo);
value = formatValue(value, valueVo, parent);
valueMap.put(originKey, value == null ? "" : value);
}
......@@ -477,7 +478,7 @@ public class SnapshotServiceImpl implements SnapshotService {
for (CustomAttributes customAttributes : customAttributesList) {
Object value = map.get(customAttributes.getColumnName());
// 格式转换
value = formatValue(value, new ValueVo(null, customAttributes.getFormatter(), customAttributes.getCodeTable(), customAttributes.getFormatter()));
value = formatValue(value, new ValueVo(null, customAttributes.getFormatter(), customAttributes.getCodeTable(), customAttributes.getFormatter()), parent);
PackListcellBo listCellData = new PackListcellBo();
listCellData.setLabel(value == null ? "" : String.valueOf(value));
listCellData.setStyle(customAttributes.getColumnStyle());
......@@ -654,16 +655,26 @@ public class SnapshotServiceImpl implements SnapshotService {
*
* @param value
* @param valueVo
* @param parent
* @return
*/
private Object formatValue(Object value, ValueVo valueVo) {
private Object formatValue(Object value, ValueVo valueVo, IModule parent) {
if (value != null) {
String format = valueVo.getFormat();
String codeTable = valueVo.getCodeTable();
String formatter = valueVo.getFormatter();
// 从码表中转换
if (StringUtils.isNotBlank(codeTable) && "{0}".equals(formatter)) {
if ("{0}".equals(formatter)) {
if (StringUtils.isNotBlank(codeTable)) {
// 静态码表
value = MdaUtils.getCodetableLabel(codeTable, (String) value);
} else {
// 动态码表
Set<ValueVo> valueVos = new HashSet<>();
valueVos.add(new ValueVo(valueVo.getKey() + "CodeTable"));
Map<String, Object> map = getValueMap(valueVos, parent);
value = MdaUtils.getCodetableLabel((List<CodetableItem>) map.get(valueVo.getKey() + "CodeTable"), (String) value);
}
}
if (StringUtils.isNotBlank(format)) {
if (value instanceof Date) {
......
......@@ -23,6 +23,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import java.io.*;
import java.math.BigDecimal;
......@@ -961,6 +962,19 @@ public class MdaUtils {
return Codetables.getCodetableLabel(key, codetable, locale.getLanguage());
}
public static String getCodetableLabel(List<CodetableItem> codeTable, String key) {
String label = "";
if (!CollectionUtils.isEmpty(codeTable)) {
for (CodetableItem codetableItem : codeTable) {
if (key.equalsIgnoreCase(codetableItem.getValue())) {
label = codetableItem.getLabel();
break;
}
}
}
return label;
}
public static String getCodetableLabel(Locale locale, String codetable, String key) {
return Codetables.getCodetableLabel(key, codetable, locale.getLanguage());
}
......@@ -1355,19 +1369,21 @@ public class MdaUtils {
}
/**
* todo
*
* @param o
*/
public static void setValues(Object... o) {
// if (o.length == 3) {
// Object o1 = o[0];
// Object o2 = o[1];
// Object o3 = o[2];
// if (o1 instanceof IModule && o2 instanceof String) {
// Datas.setFieldValue((IModule) o1, (String) o2, o3);
// }
// }
if (o.length == 3) {
Object o1 = o[0];
Object o2 = o[1];
Object o3 = o[2];
if (o1 instanceof IModule && o2 instanceof String && o3 instanceof List) {
String fieldName = (String) o2;
try {
Datas.setFieldValue((IModule) o1, fieldName + "CodeTable", o3);
} catch (Exception e) {
}
}
}
}
/**
......
......@@ -37,7 +37,7 @@ public class Systems {
private static final List<Resource> resources = new ArrayList<>();
private static final Map<String, InputStream> FILE_MAP = new HashMap<>();
private static final Map<String, ByteArrayOutputStream> FILE_MAP = new HashMap<>();
public static void setAttribute(IDatafield field, String ATTR, Object val) {
setAttribute(field.getParent(), field.getName(), ATTR, val);
......@@ -1038,12 +1038,33 @@ public class Systems {
if (FILE_MAP.size() == 0) {
for (Resource resource : resources) {
try {
FILE_MAP.put(resource.getFilename(), resource.getInputStream());
FILE_MAP.put(resource.getFilename(), cloneInputStream(resource.getInputStream()));
} catch (IOException e) {
}
}
}
return FILE_MAP.get(fileName);
ByteArrayOutputStream byteArrayOutputStream = FILE_MAP.get(fileName);
if (byteArrayOutputStream == null) {
log.error("获取快照文件{}失败", fileName);
return null;
}
return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
}
private static ByteArrayOutputStream cloneInputStream(InputStream input) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = input.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
return baos;
} catch (IOException e) {
log.error("获取快照文件失败", e);
return null;
}
}
}
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