Commit 6d4fc52e by s_guodong

支持快照

parent 06950f76
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://www.zkoss.org/2005/zul" 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">
<style src="/public/template.css"/>
<script src="/public/template.js" type="text/javascript"/>
<label multiline="true" style="position:absolute;left:140px;top:80px;height:16px;" value="姓名" zclass="z-label"/>
<textbox readonly="true" rows="1" style="position:absolute;left:240px;top:80px;height:16px;width:201.0px;ime-mode:disabled;border-bottom:solid red;" text="${nan}" zclass="z-textbox"/>
<label multiline="true" style="position:absolute;left:140px;top:120px;height:16px;" value="电话" zclass="z-label"/>
<textbox readonly="true" rows="1" style="position:absolute;left:240px;top:120px;height:16px;width:201.0px;ime-mode:disabled;border-bottom:solid red;" text="${tel}" zclass="z-textbox"/>
</window>
...@@ -3,57 +3,63 @@ package com.brilliance.mda.support.mybatis; ...@@ -3,57 +3,63 @@ package com.brilliance.mda.support.mybatis;
import com.brilliance.mda.runtime.mda.IDisplay; import com.brilliance.mda.runtime.mda.IDisplay;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.Map;
/** /**
* 快照保存器 * 快照保存器
* @author fukai
* *
* @author fukai
*/ */
@Component @Component
public class FileDisplayManager implements IDisplay { public class FileDisplayManager implements IDisplay {
@Override @Override
public boolean saveDisplay(String filePathOrKey,String data) { public boolean saveDisplay(String filePathOrKey, String data) {
File file = new File(filePathOrKey); File file = new File(filePathOrKey);
File parentFolder = file.getParentFile(); File parentFolder = file.getParentFile();
if(!parentFolder.exists() && !parentFolder.mkdirs()) if (!parentFolder.exists() && !parentFolder.mkdirs())
return false; return false;
FileWriter fr = null; FileWriter fr = null;
try{ try {
file.createNewFile(); file.createNewFile();
fr = new FileWriter(file); fr = new FileWriter(file);
IOUtils.write(data, fr); IOUtils.write(data, fr);
}catch(Exception e) } catch (Exception e) {
{ return false;
e.printStackTrace(); } finally {
return false; IOUtils.closeQuietly(fr);
} }
return true; return true;
} }
@SuppressWarnings("deprecation") @Override
@Override public boolean saveDisplay(String filePathOrKey, String templateContent, Map valueMap) {
public String readDisplay(String filePathOrKey) { String data = StrSubstitutor.replace(templateContent, valueMap);
File file = new File(filePathOrKey); return this.saveDisplay(filePathOrKey, data);
if(!file.exists()) }
return null;
FileReader fr = null; @SuppressWarnings("deprecation")
try{ @Override
fr = new FileReader(file); public String readDisplay(String filePathOrKey) {
return IOUtils.toString(fr); File file = new File(filePathOrKey);
}catch(Exception e) if (!file.exists())
{ return null;
e.printStackTrace(); FileReader fr = null;
}finally try {
{ fr = new FileReader(file);
IOUtils.closeQuietly(fr); return IOUtils.toString(fr);
} } catch (Exception e) {
return null; e.printStackTrace();
} } finally {
IOUtils.closeQuietly(fr);
}
return null;
}
} }
...@@ -3,7 +3,6 @@ package com.brilliance.mda.runtime.mda; ...@@ -3,7 +3,6 @@ package com.brilliance.mda.runtime.mda;
import com.brilliance.mda.runtime.mda.impl.EnvConfig; import com.brilliance.mda.runtime.mda.impl.EnvConfig;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
...@@ -58,6 +57,12 @@ public interface IContext extends Serializable { ...@@ -58,6 +57,12 @@ public interface IContext extends Serializable {
boolean saveDisplay(String fileName); boolean saveDisplay(String fileName);
boolean saveDisplay(IPanel[] panels, String fileName);
boolean saveDisplay(IPanel panel, String fileName);
boolean saveDisplay(String panelPath, String fileName);
int getErrorCode(); int getErrorCode();
void setErrorCode(int errorCode); void setErrorCode(int errorCode);
......
package com.brilliance.mda.runtime.mda; package com.brilliance.mda.runtime.mda;
import java.util.Map;
/** /**
* 快照保存接口,保存的东西,可以使文件路径/或者是文件保存key。具体实现由实施情况决定。 * 快照保存接口,保存的东西,可以使文件路径/或者是文件保存key。具体实现由实施情况决定。
* 可以使保存至数据库/保存至NOSQL数据库/保存至文件存储器 * 可以使保存至数据库/保存至NOSQL数据库/保存至文件存储器
...@@ -9,5 +11,8 @@ package com.brilliance.mda.runtime.mda; ...@@ -9,5 +11,8 @@ package com.brilliance.mda.runtime.mda;
*/ */
public interface IDisplay { public interface IDisplay {
boolean saveDisplay(String filePathOrKey, String data); boolean saveDisplay(String filePathOrKey, String data);
boolean saveDisplay(String filePathOrKey,String templateContent, Map valueMap);
String readDisplay(String filePathOrKey); String readDisplay(String filePathOrKey);
} }
...@@ -2,9 +2,16 @@ package com.brilliance.mda.runtime.mda.driver; ...@@ -2,9 +2,16 @@ package com.brilliance.mda.runtime.mda.driver;
import com.brilliance.mda.runtime.annotation.Transaction; import com.brilliance.mda.runtime.annotation.Transaction;
import com.brilliance.mda.runtime.mda.*; import com.brilliance.mda.runtime.mda.*;
import com.brilliance.mda.runtime.mda.impl.Argument;
import com.brilliance.mda.runtime.mda.impl.EnvConfig; import com.brilliance.mda.runtime.mda.impl.EnvConfig;
import com.brilliance.mda.runtime.request.BaseVO; import com.brilliance.mda.runtime.request.BaseVO;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.FileReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.*; import java.util.*;
import static com.brilliance.mda.runtime.mda.Constants.NO_ERROR; import static com.brilliance.mda.runtime.mda.Constants.NO_ERROR;
...@@ -12,6 +19,8 @@ import static com.brilliance.mda.runtime.mda.Constants.NO_ERROR; ...@@ -12,6 +19,8 @@ import static com.brilliance.mda.runtime.mda.Constants.NO_ERROR;
public class MdaContext implements IContext { public class MdaContext implements IContext {
private static final String DISPLAY_TEMPLATE_PATH = "displayTemplate/";
private transient final IDaoSession daoSession; private transient final IDaoSession daoSession;
private transient final EnvConfig config; private transient final EnvConfig config;
private transient final IDisplay display; private transient final IDisplay display;
...@@ -240,6 +249,47 @@ public class MdaContext implements IContext { ...@@ -240,6 +249,47 @@ public class MdaContext implements IContext {
return false; return false;
} }
@Override
public boolean saveDisplay(IPanel[] panels, String fileName) {
return false;
}
@Override
public boolean saveDisplay(IPanel panel, String fileName) {
return false;
}
@Override
public boolean saveDisplay(String panelPath, String fileName) {
IContext ctx = MdaEnv.getContext();
ctx.setErrorCode(NO_ERROR);
String templateContent = getTemplateContent(panelPath);
if (StringUtils.isBlank(templateContent)) {
return false;
}
// 根据trninr查找
int b = fileName.lastIndexOf("\\");
int e = fileName.lastIndexOf(".");
String trninr = fileName.substring(b + 1, e);
String sql = "select * from trn where inr='" + trninr + "'";
ctx.getDaoSession().dbExecuteSQL(sql);
Argument<String> objtyp = new Argument<String>("objtyp");
ctx.getDaoSession().dbFetchFields(objtyp);
ctx.getDaoSession().dbCloseCursor();
int errorCode = ctx.getErrorCode();
if (errorCode != NO_ERROR) {
return false;
}
// 将模板中需要的值放入map todo
Map valueMap = new HashMap();
valueMap.put("trninr", trninr);
if (this.display != null) {
return this.display.saveDisplay(fileName, templateContent, valueMap);
}
return false;
}
public int getErrorCode() { public int getErrorCode() {
int temp = this.errorCode; int temp = this.errorCode;
this.errorCode = NO_ERROR; this.errorCode = NO_ERROR;
...@@ -421,4 +471,28 @@ public class MdaContext implements IContext { ...@@ -421,4 +471,28 @@ public class MdaContext implements IContext {
} }
private String getTemplateContent(String panelPath) {
URL root = ClassLoader.getSystemResource("");
String filePath = null;
try {
filePath = java.net.URLDecoder.decode(root.getPath(), "utf-8");
} catch (UnsupportedEncodingException e) {
}
File file = new File(filePath + DISPLAY_TEMPLATE_PATH + panelPath + ".zul");
if (!file.exists())
return null;
FileReader fr = null;
try {
fr = new FileReader(file);
return IOUtils.toString(fr);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(fr);
}
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