2018-11-05 15:22:08 +08:00

91 lines
2.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%@ page trimDirectiveWhitespaces="true" %>
<%@ page language="java" contentType="text/html; charset=GBK"%>
<%@ page import="com.amarsoft.are.jbo.impl.BizObjectTableMapper"%>
<%@ page import="com.amarsoft.biz.formatdoc.model.FormatDocConfig"%>
<%@ page import="com.amarsoft.biz.formatdoc.model.FormatDocHelp"%>
<%@ include file="/Frame/resources/include/include_begin_ajax.jspf" %>
<%
out.print(changeHtmlData2DB(new FormatDocConfig(request), Sqlca) ? "转换成功" : "转换失败");
%>
<%@ include file="/Frame/resources/include/include_end_ajax.jspf" %>
<%!
public static boolean changeHtmlData2DB(FormatDocConfig config, Transaction Sqlca) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
String sTable = ((BizObjectTableMapper)(JBOFactory.getBizObjectManager("jbo.app.FORMATDOC_DATA"))).getTable();
conn = ARE.getDBConnection(Sqlca.getDatabase());
conn.setAutoCommit(false);
ps = conn.prepareStatement("select SerialNo, HtmlData from "+sTable);
rs = ps.executeQuery();
while(rs.next()){
changeHtmlData2xml(rs, config, conn);
}
conn.commit();
conn.close();
return true;
}catch(Exception e){
ARE.getLog().debug(e);
if(conn != null) try{
conn.rollback();
conn.close();
}catch(Exception e0){}
return false;
}finally{
if(rs != null) try{
rs.close();
}catch (Exception e) {
}
if(ps != null) try{
ps.close();
}catch (Exception e) {
}
if(conn != null) try{
conn.close();
}catch (Exception e) {
}
}
}
private static void changeHtmlData2xml(ResultSet rs, FormatDocConfig config, Connection conn) throws Exception, IOException {
InputStream is = null;
PreparedStatement ps = null;
try{
String sSerialNo = rs.getString("SerialNo");
is = rs.getBinaryStream("HtmlData");
if(is != null){
ARE.getLog().debug("SerialNo="+sSerialNo+"HtmlData字段已有值");
return;
}
String sFolder = config.getWorkDocSavePath() + "/htmldata/" + sSerialNo.substring(0,4) + "/" + sSerialNo.substring(4, 6)+ "/" + sSerialNo.substring(6, 8);
File file = new File(sFolder + "/" + sSerialNo + ".htm");
if(!file.exists()){
ARE.getLog().debug("SerialNo="+sSerialNo+"文件不存在");
return;
}
byte[] bytes = FormatDocHelp.getHtmlString(file).getBytes();
String sTable = ((BizObjectTableMapper)(JBOFactory.getBizObjectManager("jbo.app.FORMATDOC_DATA"))).getTable();
ps = conn.prepareStatement("update "+sTable+" set HtmlData = ? where SerialNo = ?");
ps.setBinaryStream(1, new ByteArrayInputStream(bytes, 0, bytes.length), bytes.length);
ps.setString(2, sSerialNo);
ps.executeUpdate();
// TODO 删除文件
}finally{
if(is != null) try{
is.close();
}catch (Exception e) {}
if(ps != null) try{
ps.close();
}catch(Exception e){}
}
}
%>