Commit aa204af7 by s_guodong

处理日期格式

parent 639dcc16
package com.brilliance.test;
import com.brilliance.mda.runtime.mda.snapshot.SnapshotServiceImpl;
import java.util.HashSet;
public class Test {
@org.junit.jupiter.api.Test
public void test(){
HashSet set=new HashSet();
public void test() {
HashSet set = new HashSet();
set.add("com");
set.add("com1");
set.add("com");
System.out.println(set.size());
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);
}
}
......@@ -3,6 +3,7 @@ package com.brilliance.mda.runtime.mda.snapshot;
import com.brilliance.mda.runtime.mda.IModule;
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.MdaUtils;
import com.brilliance.mda.runtime.mda.util.XmlUtil;
import org.apache.commons.lang3.StringUtils;
......@@ -54,6 +55,7 @@ public class SnapshotServiceImpl implements SnapshotService {
DocumentBo documentBo = XmlUtil.unmarshToObjBinding(DocumentBo.class, file);
return documentBo;
} catch (Exception e) {
log.error("模板{}解析失败", panelPath, e);
}
return null;
}
......@@ -159,7 +161,7 @@ public class SnapshotServiceImpl implements SnapshotService {
for (CustomAttributes customAttribute : customAttributes) {
text = customAttribute.getFieldUrl();
if (StringUtils.isNotBlank(text)) {
keySet.add(text);
keySet.add(text + ":" + textboxBo.getFormat());
break;
}
}
......@@ -244,12 +246,18 @@ public class SnapshotServiceImpl implements SnapshotService {
*/
private void getValueFromModule(Map<String, Object> valueMap, IModule parent, String key) {
String originKey = key;
String format = "";
if (key.contains(":")) {
String[] split = key.split(":");
originKey = split[0];
format = split[1];
}
if (key.startsWith("\\")) {
key = key.substring(1);
}
String[] split = key.split("\\\\");
Class aClass = parent.getClass();
Object value = "";
Object value = null;
Object obj = parent;
for (int i = 0; i < split.length; i++) {
String s = split[i];
......@@ -265,6 +273,10 @@ public class SnapshotServiceImpl implements SnapshotService {
log.error("获取模板中的值{}错误:", originKey, e);
}
}
if (value != null && StringUtils.isNotBlank(format)) {
value = DateUtil.format((Date) value, format.replaceAll("/", "-"));
}
valueMap.put(originKey, value == null ? "" : value);
}
......
package com.brilliance.mda.runtime.mda.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/21
*/
public class DateUtil {
public static String format(Date date, String pattern) {
DateFormat dateFormat = new SimpleDateFormat(pattern);
return date != null ? dateFormat.format(date) : null;
}
}
......@@ -19,26 +19,22 @@ public class XmlUtil {
/**
* 将XML格式的文件转换成JAXB实现对象
*/
public static <T> T unmarshToObjBinding(Class<T> tclz, File file) {
try {
JAXBContext jc = jaxbContextMap.get(tclz);
if (jc == null) {
jc = JAXBContext.newInstance(tclz);
jaxbContextMap.put(tclz, jc);
}
Unmarshaller un = jc.createUnmarshaller();
sax.setNamespaceAware(false);
XMLReader xmlReader = sax.newSAXParser().getXMLReader();
Source source = new SAXSource(xmlReader, new InputSource(
new FileInputStream(file)));
Object obj = un.unmarshal(source);
if (JAXBElement.class.isAssignableFrom(obj.getClass())) {
obj = (T) JAXBIntrospector.getValue(obj);
}
return (T) obj;
} catch (Exception e) {
public static <T> T unmarshToObjBinding(Class<T> tclz, File file) throws Exception {
JAXBContext jc = jaxbContextMap.get(tclz);
if (jc == null) {
jc = JAXBContext.newInstance(tclz);
jaxbContextMap.put(tclz, jc);
}
return null;
Unmarshaller un = jc.createUnmarshaller();
sax.setNamespaceAware(false);
XMLReader xmlReader = sax.newSAXParser().getXMLReader();
Source source = new SAXSource(xmlReader, new InputSource(
new FileInputStream(file)));
Object obj = un.unmarshal(source);
if (JAXBElement.class.isAssignableFrom(obj.getClass())) {
obj = (T) JAXBIntrospector.getValue(obj);
}
return (T) obj;
}
......@@ -60,6 +56,7 @@ public class XmlUtil {
u.marshal(t, sw);
xmlstr = sw.toString();
} catch (Exception e) {
}
return xmlstr;
}
......
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