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;
import com.brilliance.mda.runtime.mda.IDisplay;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Map;
/**
* 快照保存器
* @author fukai
*
* @author fukai
*/
@Component
public class FileDisplayManager implements IDisplay {
@Override
public boolean saveDisplay(String filePathOrKey,String data) {
File file = new File(filePathOrKey);
File parentFolder = file.getParentFile();
if(!parentFolder.exists() && !parentFolder.mkdirs())
return false;
FileWriter fr = null;
try{
file.createNewFile();
fr = new FileWriter(file);
IOUtils.write(data, fr);
}catch(Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
@SuppressWarnings("deprecation")
@Override
public String readDisplay(String filePathOrKey) {
File file = new File(filePathOrKey);
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;
}
@Override
public boolean saveDisplay(String filePathOrKey, String data) {
File file = new File(filePathOrKey);
File parentFolder = file.getParentFile();
if (!parentFolder.exists() && !parentFolder.mkdirs())
return false;
FileWriter fr = null;
try {
file.createNewFile();
fr = new FileWriter(file);
IOUtils.write(data, fr);
} catch (Exception e) {
return false;
} finally {
IOUtils.closeQuietly(fr);
}
return true;
}
@Override
public boolean saveDisplay(String filePathOrKey, String templateContent, Map valueMap) {
String data = StrSubstitutor.replace(templateContent, valueMap);
return this.saveDisplay(filePathOrKey, data);
}
@SuppressWarnings("deprecation")
@Override
public String readDisplay(String filePathOrKey) {
File file = new File(filePathOrKey);
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;
}
}
......@@ -3,7 +3,6 @@ package com.brilliance.mda.runtime.mda;
import com.brilliance.mda.runtime.mda.impl.EnvConfig;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
......@@ -58,6 +57,12 @@ public interface IContext extends Serializable {
boolean saveDisplay(String fileName);
boolean saveDisplay(IPanel[] panels, String fileName);
boolean saveDisplay(IPanel panel, String fileName);
boolean saveDisplay(String panelPath, String fileName);
int getErrorCode();
void setErrorCode(int errorCode);
......
package com.brilliance.mda.runtime.mda;
import java.util.Map;
/**
* 快照保存接口,保存的东西,可以使文件路径/或者是文件保存key。具体实现由实施情况决定。
* 可以使保存至数据库/保存至NOSQL数据库/保存至文件存储器
......@@ -9,5 +11,8 @@ package com.brilliance.mda.runtime.mda;
*/
public interface IDisplay {
boolean saveDisplay(String filePathOrKey, String data);
boolean saveDisplay(String filePathOrKey,String templateContent, Map valueMap);
String readDisplay(String filePathOrKey);
}
......@@ -2,9 +2,16 @@ package com.brilliance.mda.runtime.mda.driver;
import com.brilliance.mda.runtime.annotation.Transaction;
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.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 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 {
private static final String DISPLAY_TEMPLATE_PATH = "displayTemplate/";
private transient final IDaoSession daoSession;
private transient final EnvConfig config;
private transient final IDisplay display;
......@@ -240,6 +249,47 @@ public class MdaContext implements IContext {
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() {
int temp = this.errorCode;
this.errorCode = NO_ERROR;
......@@ -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