package com.extUi; import java.util.ArrayList; import org.apache.log4j.Logger; import com.extUi.form.FormImpl; import com.extUi.form.Formable; import com.extUi.grid.GridImpl; import com.extUi.grid.Gridable; import com.sysmodel.XFormFactory; import com.sysmodel.collectmodel.xmlmodel.able.FormCollection; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.MdpClass; import com.sysmodel.datamodel.xmlmodel.able.MdpModule; import com.sysmodel.datamodel.xmlmodel.able.SysModel; import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl; import com.toolkit.file.FileOperate; public class ExtUiImp implements ExtUiable{ private final static Logger log = Logger.getLogger(ExtUiImp.class); private static SysModel sysmodel = ModelFactory.getSysmodel(); private static Gridable Gridable = new GridImpl(); private static Formable Formable = new FormImpl(); public String getHtmlPathByModuleCode(String Code) { String result = ""; MdpModule mdpmod = sysmodel.getMdpModuleByCode(Code); String fromXmlFolder = sysmodel.getFileLoadFolder(); fromXmlFolder = fromXmlFolder.replace("WEB-INF", "page"); String fromPackageName = mdpmod.getPackageName().replaceFirst("com.sinosoft.", "") .replace("lz.", ""); result = fromXmlFolder + fromPackageName.replace(".", "\\"); // 这段代码替换\到/ 字符串替换 result = result.replaceAll("\\\\", "/"); // log.info(result); return result; } public String getResourcePathByModuleCode(String Code) { String result = ""; String temp = getHtmlPathByModuleCode(Code); temp = temp.substring(temp.indexOf("page")); result = "../"; while (temp.indexOf("/") != -1) { result += "../"; temp = temp.substring(temp.indexOf("/") + 1); }; // log.info(result); return result; } public StringBuffer getFormJs(String pageid) { return Formable.getFormJs(pageid); } public String getFormHtmlNameById(String pageid) { String result = ""; FormCollection FormCollection = XFormFactory.getXFormModel().getFormCollection(pageid); String[] tables = FormCollection.getClassidArry(); MdpClass mdpClass = null; for (int i = 0; i < tables.length; i++) { String temp1 = (String) tables[i]; mdpClass = sysmodel.getMdpClassByClassID(Integer.parseInt(temp1)); result += mdpClass.getName().replaceFirst(mdpClass.getType() + "_", ""); } result = result.replace("_", ""); return result + "edit.html"; } public String creatFormHtmlJsFile(String pageid) { FormCollection FormCollection = XFormFactory.getXFormModel().getFormCollection(pageid); String outputPath = this.getHtmlPathByModuleCode(FormCollection.getType()); String ResourcePath = this.getResourcePathByModuleCode(FormCollection.getType()); StringBuffer sb = new StringBuffer(); sb.append("\n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" " + FormCollection.getDescription() + FormCollection.getPageid() + "\n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(""); log.info("\n" + sb.toString()); FileOperate FileOperate = new FileOperate(); boolean bsuccess = FileOperate.createFile(getFormHtmlNameById(pageid), outputPath, sb.toString(), "UTF-8", false); sb = new StringBuffer(); sb.append("【" + FormCollection.getPageid() + "】: 正在生成采集页面“" + FormCollection.getDescription() + "” ...
"); sb.append(""); sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + getFormHtmlNameById(pageid)); sb.append("
"); return sb.toString(); } public String creatFormJsFile(String pageid) { FormCollection FormCollection = XFormFactory.getXFormModel().getFormCollection(pageid); String outputPath = this.getHtmlPathByModuleCode(FormCollection.getType()); StringBuffer sb = new StringBuffer(); String jsFileName = getFormHtmlNameById(pageid).replace(".html", ".js"); sb.append("function getEditForm(Win){\n"); sb.append(this.getFormJs(pageid)); sb.append(" return fsf;\n"); sb.append("}\n"); FileOperate FileOperate = new FileOperate(); boolean bsuccess = FileOperate.createFile(jsFileName, outputPath, sb.toString(), "UTF-8", false); sb = new StringBuffer(); sb.append("【" + FormCollection.getPageid() + "】: 正在生成采集JS函数“" + FormCollection.getDescription() + "” ...
"); sb.append(""); sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + jsFileName); sb.append("
"); return sb.toString(); } public String creatJsFile(String pageid, String listid) { FormCollection formCollection = XFormFactory.getXFormModel().getFormCollection(pageid); String outputPath = this.getHtmlPathByModuleCode(formCollection.getType()); StringBuffer sb = new StringBuffer(); String jsFileName = getFormHtmlNameById(pageid).replace(".html", ".js"); MdpModule mdpmod = sysmodel.getMdpModuleByCode(formCollection.getType()); sb.append("/**\n"); sb.append(" * @class \n"); sb.append(" * @author \n"); sb.append(" * @deprecated "); sb.append(mdpmod.getDescription());// 类说明 sb.append(" \n"); sb.append(" */\n"); sb.append("Ext.namespace('" + mdpmod.getPackageName() + "');\n"); sb.append(mdpmod.getPackageName()); sb.append("."); sb.append(sysmodel.getMdpClassByClassID(Integer.valueOf(formCollection.getClassid())) .getName().replace("_", "")); sb.append("= function() {\n"); sb.append("var _this = this;\n"); sb.append("\n"); sb.append("// 私有属性\n"); sb.append("\n"); sb.append("// 公有属性\n"); sb.append("_this.listGrid = null;\n"); sb.append("_this.queryFrom = null;\n"); sb.append("_this.editFrom = null;\n"); sb.append("// 私有方法\n"); sb.append("\n"); // 生成form表单 sb.append(this.getFormJs(pageid)); sb.append("// 公有方法\n"); sb.append("/**\n"); sb.append(" * 新增用户 参数-obj 数据对象,json格式\n"); sb.append(" */\n"); sb.append("_this.add = function(obj) {\n"); sb.append("\n"); sb.append("com.sinosoft.common.utils.Request.add(\n"); sb.append("'../ws/crud/CRUDService/create', obj, function() {\n"); sb.append("// 成功后需要执行的动作\n"); sb.append("\n"); sb.append("// 刷新列表数据\n"); sb.append("var ds = _this.listGrid.getStore();\n"); sb.append("ds.reload();\n"); sb.append("// 成功后自动关闭 新增表单窗口-调用框架方法\n"); sb.append("com.sinosoft.common.frameWork.FrameWork.hideWin();\n"); sb.append("\n"); sb.append("});\n"); sb.append("}\n"); sb.append(" /**\n"); sb.append(" * 显示详细信息\n"); sb.append(" */\n"); sb.append(" _this.showInfo = function() {\n"); sb.append(" // 获取用户选择的列\n"); sb.append(" var sm = _this.listGrid.getSelectionModel();\n"); sb.append(" if (sm.getCount() == 1) {\n"); sb.append(" // 获取数据id\n"); sb.append(" var FD_OBJECTID = sm.getSelected().get('FD_OBJECTID" + formCollection.getClassid() + "');\n"); sb.append(" // 构造传给服务的参数,\n"); sb.append(" var params = {\n"); sb.append(" objectID : FD_OBJECTID,\n"); sb.append("classid : '"); sb.append(formCollection.getClassid()); sb.append("'\n"); sb.append(" };\n"); sb.append(" com.sinosoft.common.utils.Request.query(\n"); sb.append(" '../ws/crud/CRUDService/getDataById/', params, function(obj) {\n"); sb.append(" // 成功后需要执行的动作\n"); sb.append(" var infoWin = new Ext.Window({\n"); sb.append(" layout : 'fit',\n"); sb.append(" width : 600,\n"); sb.append(" draggable : true, // 不允许拖动\n"); sb.append(" modal : false,\n"); sb.append(" maximizable : true,\n"); sb.append(" minimizable : false,\n"); sb.append(" autoDestroy : true,\n"); sb.append(" height : 400,\n"); sb.append(" autoHeight : false,\n"); sb.append(" autoScroll : true,\n"); sb.append(" title : '详细信息',\n"); sb.append(" closable : true,\n"); sb.append(" closeAction : 'close'\n"); sb.append(" });\n"); sb.append(" infoWin.show();\n"); sb.append(Gridable.getTpl(listid)); sb.append(" tpl.overwrite(infoWin.body, obj);\n"); sb.append("});\n"); sb.append("} else {\n"); sb.append("// 提示用户删除操作必须选择记录--调用模型框架显示\n"); sb.append("com.sinosoft.common.frameWork.FrameWork.showMsg('info', '请选择一条记录!');\n"); sb.append("}\n"); sb.append("};\n"); sb.append("/**\n"); sb.append(" * 修改用户信息 参数-obj 数据对象,josn格式\n"); sb.append(" */\n"); sb.append("_this.edit = function(obj) {\n"); sb.append("\n"); sb.append("com.sinosoft.common.utils.Request.update(\n"); sb.append("'../ws/crud/CRUDService/update', obj, function() {\n"); sb.append("// 成功后需要执行的动作\n"); sb.append("\n"); sb.append("// 刷新列表数据\n"); sb.append("var ds = _this.listGrid.getStore();\n"); sb.append("ds.reload();\n"); sb.append("// 成功后自动关闭 新增表单窗口-调用框架方法\n"); sb.append("com.sinosoft.common.frameWork.FrameWork.hideWin();\n"); sb.append("});\n"); sb.append("}\n"); sb.append("/**\n"); sb.append(" * 删除用户 参数:无\n"); sb.append(" */\n"); sb.append("_this.del = function(button, text) {\n"); sb.append("\n"); sb.append("if (button == 'yes') {\n"); sb.append("// 获取用户选择的列\n"); sb.append("var sm = _this.listGrid.getSelectionModel();\n"); sb.append("if (sm.getCount() > 0) {\n"); sb.append("// 构造需要删除的对象的 FD_OBJECTID 用逗号(,) 分隔\n"); sb.append("var ids = '';\n"); sb.append("var selections = sm.getSelections();\n"); sb.append("for (var i = 0; i < selections.length; i++) {\n"); sb.append("ids += selections[i].get('FD_OBJECTID" + listid + "') + ',';\n"); sb.append("}\n"); sb.append("// 构造传给服务的参数,objectIDs---要删除的对象的id集合,classid--要删除的表的id\n"); sb.append("\n"); sb.append("var params = {\n"); sb.append("objectIDs : ids,\n"); sb.append("classid : '"); sb.append(formCollection.getClassid()); sb.append("'\n"); sb.append("};\n"); sb.append("// 调用框架 的删除请求服务\n"); sb.append("// 参数 url---删除服务的地址,默认为ws/crud/CRUDService/delete/\n"); sb.append("// 参数params ---传给服务的参数,\n"); sb.append("// sucFun---删除成功后的回调函数,一般为刷新列表数据,可以添加自己的业务函数\n"); sb.append("com.sinosoft.common.utils.Request.del(\n"); sb.append("'../ws/crud/CRUDService/delete/', params,\n"); sb.append("function() {\n"); sb.append("// 成功后需要执行的动作\n"); sb.append("\n"); sb.append("// 刷新列表数据\n"); sb.append("var ds = _this.listGrid.getStore();\n"); sb.append("ds.reload();\n"); sb.append("\n"); sb.append("});\n"); sb.append("}\n"); sb.append("}\n"); sb.append("\n"); sb.append("}\n"); sb.append("/**\n"); sb.append(" * 查询函数\n"); sb.append(" */\n"); sb.append("_this.query = function() {\n"); sb.append("// 获取查询条件-根据表单内容构造查询 条件\n"); sb.append("var params = _this.queryFrom.getForm().getValues();\n"); sb.append("// 加载数据\n"); sb.append("var ds = _this.listGrid.getStore();\n"); sb.append("ds.load({\n"); sb.append("params : params\n"); sb.append("});\n"); sb.append("\n"); sb.append("}\n"); sb.append("/**\n"); sb.append(" * 显示新增表单\n"); sb.append(" * \n"); sb.append(" */\n"); sb.append("_this.showAddPanel = function() {\n"); sb.append("getEditFrom();\n"); sb.append("com.sinosoft.common.frameWork.FrameWork.openWin(_this.editFrom, 500,\n"); sb.append("500, '新增');\n"); sb.append("\n"); sb.append("}\n"); sb.append("/**\n"); sb.append(" * 显示编辑表单\n"); sb.append(" */\n"); sb.append("_this.showEditPanel = function() {\n"); sb.append("var sm = _this.listGrid.getSelectionModel();\n"); sb.append("if (sm.getCount() == 1) {\n"); sb.append("var record = sm.getSelected();\n"); sb.append("if (_this.editFrom != null) {\n"); sb.append("getEditFrom();\n"); sb.append("com.sinosoft.common.frameWork.FrameWork.openWin(_this.editFrom,\n"); sb.append("500, 500, '修改');\n"); sb.append("\n"); sb.append("_this.editFrom.getForm().loadRecord(record);\n"); sb.append("} else {\n"); sb.append("getEditFrom();\n"); sb.append("com.sinosoft.common.frameWork.FrameWork.openWin(_this.editFrom,\n"); sb.append("500, 500, '修改');\n"); sb.append("_this.editFrom.getForm().loadRecord(record);\n"); sb.append("}\n"); sb.append("\n"); sb.append("}\n"); sb.append("\n"); sb.append("}\n"); sb.append("/**\n"); sb.append(" * 显示删除确认框\n"); sb.append(" */\n"); sb.append("_this.showDelcon = function(obj) {\n"); sb.append("// 获取用户选择的列\n"); sb.append("var sm = _this.listGrid.getSelectionModel();\n"); sb.append("if (sm.getCount() > 0) {\n"); sb.append("\n"); sb.append("Ext.MessageBox.confirm('系统提示', '您确定删除这些数据吗?', _this.del);\n"); sb.append("} else {\n"); sb.append("// 提示用户删除操作必须选择记录--调用模型框架显示\n"); sb.append("com.sinosoft.common.frameWork.FrameWork.showMsg('info',\n"); sb.append("'请选择要删除的记录!');\n"); sb.append("}\n"); sb.append("\n"); sb.append("}\n"); sb.append("\n"); sb.append("\n"); sb.append(this.getGridJs(listid)); sb.append("\n"); sb.append("}\n"); FileOperate FileOperate = new FileOperate(); boolean bsuccess = FileOperate.createFile(jsFileName, outputPath, sb.toString(), "UTF-8", false); sb = new StringBuffer(); sb.append("【" + formCollection.getPageid() + "】: 正在生成采集JS函数“" + formCollection.getDescription() + "” ...
"); sb.append(""); sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + jsFileName); sb.append("
"); return sb.toString(); } public String getGridHtmlNameById(String listid) { String result = ""; FormListImpl FormList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid); ArrayList tables = FormList.getQueryTables(); MdpClass mdpClass = null; for (int i = 0; i < tables.size(); i++) { String temp1 = (String) tables.get(i); mdpClass = sysmodel.getMdpClassByClassID(Integer.parseInt(temp1)); result += mdpClass.getName().replaceFirst(mdpClass.getType() + "_", ""); } result = result.replace("_", ""); return result + "list.html"; } public StringBuffer getGridJs(String listid) { return Gridable.getGridJs(listid); } public String creatGridHtmlJsFile(String listid) { FormListImpl FormList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid); String outputPath = this.getHtmlPathByModuleCode(FormList.getType()); String ResourcePath = this.getResourcePathByModuleCode(FormList.getType()); StringBuffer sb = new StringBuffer(); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); sb.append(" " + FormList.getDescription() + FormList.getListid() + "\n"); sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); if (FormList.getQueryFields().size() > 0) { sb.append(" \n"); } sb.append(" \n"); sb.append(" \n"); /** * 引入页面的CSS,JS等 */ sb.append(FormList.getInclude() + "\n"); sb.append(this.getGridJs(listid)); sb.append(" \n"); sb.append(" \n"); // 列表显示的div sb.append("
\n"); if (FormList.getQueryFields().size() > 0 || FormList.getListAction().size() > 0) { sb.append("
\n"); sb.append("
" + FormList.getListHead().getTitle() + "
\n"); sb.append("
\n"); sb.append("
\n"); sb.append("
\n"); sb.append("
" + FormList.getListHead().getTitle() + "
\n"); sb.append("
\n"); sb.append("
\n"); } sb.append(" \n"); sb.append(""); log.info("生成文件名称:" + getGridHtmlNameById(listid)); log.info("生成文件路径:" + outputPath); log.info("\n" + sb.toString()); FileOperate FileOperate = new FileOperate(); boolean bsuccess = FileOperate.createFile(getGridHtmlNameById(listid), outputPath, sb.toString(), "UTF-8", false); sb = new StringBuffer(); sb.append("【" + FormList.getListid() + "】: 正在生成列表“" + FormList.getDescription() + "” 页面...
"); sb.append(""); sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + getGridHtmlNameById(listid)); sb.append("
"); return sb.toString(); } public String creatQueryJsFile(String listid) { FormListImpl formlist = (FormListImpl) XFormFactory.getXFormModel().getFormList(listid); String outputPath = this.getHtmlPathByModuleCode(formlist.getType()); StringBuffer sb = new StringBuffer(); String jsFileName = getGridHtmlNameById(listid).replace(".html", ".js"); MdpModule mdpmod = sysmodel.getMdpModuleByCode(formlist.getType()); int classid = 0; if (formlist.getQueryFields().size() > 0) { classid = formlist.getQueryFields().get(0).getClassid(); } sb.append("/**\n"); sb.append(" * @class \n"); sb.append(" * @author \n"); sb.append(" * @deprecated "); sb.append(mdpmod.getDescription());// 类说明 sb.append(" \n"); sb.append(" */\n"); sb.append("Ext.namespace('" + mdpmod.getPackageName() + "');\n"); sb.append(mdpmod.getPackageName()); sb.append("."); sb.append(sysmodel.getMdpClassByClassID(classid).getName().replace("_", "")); sb.append("= function() {\n"); sb.append("var _this = this;\n"); sb.append("\n"); sb.append("// 私有属性\n"); sb.append("\n"); sb.append("// 公有属性\n"); sb.append("_this.listGrid = null;\n"); sb.append("_this.queryFrom = null;\n"); sb.append("// 私有方法\n"); sb.append("\n"); sb.append("// 公有方法\n"); sb.append("/**\n"); sb.append(" */\n"); sb.append(" /**\n"); sb.append(" * 显示详细信息\n"); sb.append(" */\n"); sb.append(" _this.showInfo = function() {\n"); sb.append(" // 获取用户选择的列\n"); sb.append(" var sm = _this.listGrid.getSelectionModel();\n"); sb.append(" if (sm.getCount() == 1) {\n"); sb.append(" // 获取数据id\n"); sb.append(" var FD_OBJECTID = sm.getSelected().get('FD_OBJECTID" + classid + "');\n"); sb.append(" // 构造传给服务的参数,\n"); sb.append(" var params = {\n"); sb.append(" objectID : FD_OBJECTID,\n"); sb.append("classid : '"); sb.append(classid); sb.append("'\n"); sb.append(" };\n"); sb.append(" com.sinosoft.common.utils.Request.query(\n"); sb.append(" '../ws/crud/CRUDService/getDataById/', params, function(obj) {\n"); sb.append(" // 成功后需要执行的动作\n"); sb.append(" var infoWin = new Ext.Window({\n"); sb.append(" layout : 'fit',\n"); sb.append(" width : 600,\n"); sb.append(" draggable : true, // 不允许拖动\n"); sb.append(" modal : false,\n"); sb.append(" maximizable : true,\n"); sb.append(" minimizable : false,\n"); sb.append(" autoDestroy : true,\n"); sb.append(" height : 400,\n"); sb.append(" autoHeight : false,\n"); sb.append(" autoScroll : true,\n"); sb.append(" title : '详细信息',\n"); sb.append(" closable : true,\n"); sb.append(" closeAction : 'close'\n"); sb.append(" });\n"); sb.append(" infoWin.show();\n"); sb.append(Gridable.getTpl(listid)); sb.append(";\n"); sb.append(" tpl.overwrite(infoWin.body, obj);\n"); sb.append("});\n"); sb.append("};\n"); sb.append("}\n"); sb.append("/**\n"); sb.append(" * 列表导出EXCEL 参数-_this.listGrid 数据对象无\n"); sb.append(" */\n"); // 导出EXCEL函数 sb.append(this.getExcelFunction()); sb.append("/**\n"); sb.append(" * 查询函数\n"); sb.append(" */\n"); sb.append("_this.query = function() {\n"); sb.append("// 获取查询条件-根据表单内容构造查询 条件\n"); sb.append("var params = _this.queryFrom.getForm().getValues();\n"); sb.append("// 加载数据\n"); sb.append("var ds = _this.listGrid.getStore();\n"); sb.append("ds.load({\n"); sb.append("params : params\n"); sb.append("});\n"); sb.append("\n"); sb.append("}\n"); sb.append("/**\n"); sb.append("\n"); sb.append("\n"); sb.append(this.getGridForQuery(listid)); sb.append("\n"); sb.append("}\n"); FileOperate FileOperate = new FileOperate(); boolean bsuccess = FileOperate.createFile(jsFileName, outputPath, sb.toString(), "UTF-8", false); sb = new StringBuffer(); sb.append("【" + formlist.getListid() + "】: 正在生成采集JS函数“" + formlist.getDescription() + "” ...
"); sb.append(""); sb.append("文件" + bsuccess + "发布到:" + outputPath + "/" + jsFileName); sb.append("
"); return sb.toString(); } private String getExcelFunction() { StringBuffer sb = new StringBuffer(); sb.append("_this.exportExcel = function(grid) {\n"); sb.append("var ds = new Ext.data.Store({// 这是数据源\n"); sb.append(" proxy : grid.store.proxy,\n"); sb.append(" baseParams : grid.store.baseParams,\n"); sb.append(" reader : grid.store.reader\n"); sb.append("});\n\n"); sb.append("var dd = grid.store.baseParams;\n"); sb.append("ds.load({\n"); sb.append(" start : 0,\n"); sb.append(" limit : 2000\n"); sb.append("});\n"); sb.append("var vExportContent = grid.getExcelXml(true);\n"); sb.append("if (Ext.isIE6 || Ext.isIE7 || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3) {\n"); sb.append("var fd = Ext.get('frmDummy');\n"); sb.append("if (!fd) {\n"); sb.append(" fd = Ext.DomHelper.append(Ext.getBody(), {\n"); sb.append(" tag : 'form',\n"); sb.append(" method : 'post',\n"); sb.append(" id : 'frmDummy',\n"); sb.append(" action : 'toExcel/exportexcel.jsp',\n"); sb.append(" target : '_blank',\n"); sb.append(" name : 'frmDummy',\n"); sb.append(" cls : 'x-hidden',\n"); sb.append(" cn : [{\n"); sb.append(" tag : 'input',\n"); sb.append(" name : 'exportContent',\n"); sb.append(" id : 'exportContent',\n"); sb.append(" type : 'hidden'\n"); sb.append("}]\n"); sb.append("}, true);\n"); sb.append("}\n"); sb.append(" fd.child('#exportContent').set({\n"); sb.append(" value : vExportContent\n"); sb.append(" });\n"); sb.append(" fd.dom.submit();\n"); sb.append("} else {\n"); sb.append(" document.location = 'data:application/vnd.ms-excel;base64,'\n"); sb.append(" + Base64.encode(vExportContent);\n"); sb.append("}\n"); sb.append("}\n"); return sb.toString(); } private StringBuffer getGridForQuery(String listid) { return Gridable.getGridJsForQuery(listid); } }