/** * 扫描包的工具,代码生成器--兼容平台的版本 * @author weidy@2021/08/21 */ layui.define(['layer','element','form','table','upload'],function(exports){ 'use strict'; var Class = function(){ this.MODELNAME = "platform/objectService/OsCodeGeneratorComp"; this.moduleKey = "OsCodeGeneratorComp"; this.backPath = configData.compatibility? path:configData.objectServicePath; this.url = { controller:'codeGenSchemaController/', dataGrid:'gridSchema', referBtmType:'btmTypeController/referDataGrid', add:'addSchema', edit:'editSchema', preview:'previewCodeFile', downloadFile:'downloadCodeFile', productCodeFile:'productCodeFile', getObjectByOid:'getObjectByOid', getBtmTypeByOid:'btmTypeController/getBtmTypeByOid' }; this.getContent=function(){//返回这个组件的基础html var that = this; var html = ""; html = [ '
', '
', '
', '', '
', '
', that.getToolbarHtml(), '
', '', '
', '
', '
' ].join(""); return html; }; this.getToolbarHtml =function(){ var that = this; var head =['
']; var html = []; html.push([ '扫描包', '', '' ].join('')); html.push('
'); return head.join("") + html.join(""); }; this.init = function(){ var that = this; $webUtil.copyConfig(that,that.moduleKey); layui.element.init(); that.initMainTable(); that.createSearchHtml(); }; this.initMainTable = function () { var that = this; var table = layui.table; that.checkColumns(); that.firstGridLoad = false; table.render({ elem: '#table_' + that.id, id: 'table_' + that.id, url: that.url.controller + that.url.dataGrid, backPath:that.backPath, page: { limit: 20, page: 1 }, selectMode:table.selectMode.muti, cols: [that.columns], done:function(res,cur,total){ if(!that.fristMainLoad ){ table.on('tool(' + that.id + ')',function(obj){ var data = obj.data;//当前选择行的数据 var layEvent = obj.event;//点的是什么按钮 if(layEvent == 'CONFIG'){ that.editSchema(data.oid,data.id,data.name); }else if(layEvent == 'PRODUCT'){ that.productCodeFile(data.oid); }else if(layEvent == 'PREVIEW'){ that.previewCodeFile(data.oid,data.name); }else{ that.downloadCodeFile(data.oid); } }); } that.fristMainLoad = true; }, }); }; this.panelTypeCombox = [{ "key":"tree", "value":"树形" },{ "key":"table", "value":"表格" },{ "key":"table_tree", "value":"树表" },{ "key":"form", "value":"表单" }]; this.createSearchHtml = function () { var that=this; $webUtil.createSearchHtml({ id:'业务类型英文名称', name:'业务类型中文名称' },$("[layui-filter='toolbar_button_" + that.id + "']"),'table_' + that.id); $webUtil.bindDefultButtonLisenter(that, that.id); document.getElementById("toolbar_column_" + that.id).innerHTML = '配置' + '生成' + '预览' + '下载' ; }; this.SCAN = function () { var that = this; var packName = $("#" + that.id + "_pack").val(); if($webUtil.isNull(packName)){ $webUtil.showErrorMsg("请您先输入包名"); return false; } $webUtil.post('scanAnnotationController/scanAnnotation',{packName:packName},function (result) { if(result.success){ $webUtil.showMsgFromResult(result,"扫描注解成功,请等待一会检查一下业务类型的数据库表是否创建完成"); }else{ $webUtil.showErrorMsg(result.msg); } }); }; this.checkColumns = function(){ var that = this; var table = layui.table; if(that.columns==null || that.columns.length==0){ that.columns = [table.getIndexColumn(),{ field:'id', title:'业务类型英文', width:130 },{ field:'name', title:'业务类型中文', width:150 },{ field:'description', title:'描述', width:150 },{ field:'author', title:'作者', width:100 },{ field:'lastProductDate', title:'最后生成时间', width:135, templet:function(d){ return $webUtil.formateDateTimeNoSecond(d.lastProductDate); } },{ field:'options', title:'操作', width:300, toolbar: '#toolbar_column_' + that.id }]; } }; this.refresh = function(){ var that = this; layui.table.reload("table_" + that.id); }; this.ADDBYBTMTYPE = function(){ var that = this; var filter = "btmtype_" + that.id; var auditedHistory =$webUtil.dialog({ title: '从业务类型中选择添加的方案', btn:['下一步(配置方案)','取消'], content: '
', fullScreen:true, resize: false, success: function (layero) { var table = layui.table; that.checkBtmTypeColumns();//主列表中列。 table.render({ elem: '#dialog_table' + filter, id: 'dialog_table' + filter, backPath:that.backPath, url:that.url.referBtmType, selectMode:table.selectMode.single, cols: [that.btmTypeColumns], page:{ limit:25, page:1 } }); $webUtil.createSearchHtml({ id:'业务类型英文名称', name:'业务类型中文名称' },$("[layui-filter='toolbar_button_" + filter + "']"),'dialog_table' + filter); }, yes:function(){ var table = layui.table; var oid = $webUtil.getOidFromGrid('dialog_table' + filter,true,true); if(!oid){ return false; } $webUtil.get(that.url.getBtmTypeByOid,{oid:oid},function(result) { if (result.success) { layer.close(auditedHistory); var btmType = result.obj; var defaultValueByBtm = { pkBtmType: btmType.oid, id: btmType.id, name: btmType.name, } //其他几个只能是依靠变更的事件来加 //是否有自参照的类型 if(btmType.attributes){ layui.each(btmType.attributes,function(_index,attribute){ if(attribute.referBtmTypeId && attribute.referBtmTypeId.toUpperCase() == btmType.id.toUpperCase()){ defaultValueByBtm.westLayoutPanelType = 'tree'; defaultValueByBtm.westNextRegionParam = '{' + attribute.id + ':that.currentItemAttributes.oid}'; //西区的按钮也添加上 return true; } }) } //是不是平台通用的生命周期 if(btmType.lifeCycleFlag && btmType.lifeCycleId && btmType.lifeCycleId == 'frameworkDataLc'){ defaultValueByBtm.centerButtons = '{ADD:"添加",EDIT:"修改",DEL:"删除",ADVQUERY:"查询",refresh:"刷新",DISABLE:"停用",ENABLE:"启用"}'; }else { defaultValueByBtm.centerButtons = '{ADD:"添加",EDIT:"修改",DEL:"删除",ADVQUERY:"查询",refresh:"刷新"}'; } that.editSchema(null, defaultValueByBtm.id, defaultValueByBtm.name, defaultValueByBtm); } }); }, btn2:function(layero){ that.refresh(); layer.close(auditedHistory); } }); }; this.checkBtmTypeColumns = function(){ var that = this; var table = layui.table; if(that.btmTypeColumns==null || that.btmTypeColumns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列 that.btmTypeColumns = [table.getIndexColumn(),table.getCheckColumn(),{ field:'id', title:'业务类型英文', width:130 },{ field:'name', title:'业务类型中文', width:150 },{ field:'description', title:'描述', width:150 }]; } }; this.editSchema = function(schemaOid,btmTypeId,btmTypeName,defaultValueByBtm){ var that = this; var isEdit = true; if(defaultValueByBtm && $webUtil.isNotNull(defaultValueByBtm.pkBtmType)){ //说明是新增 isEdit = false; } var form = layui.form; var filter = that.id + "_addOrSchema" ; var addOrEditIndex = $webUtil.dialog({ targetObject:that, title: isEdit?'配置生成方案':'新增代码生成方案', btn: ['保存', '取消'], content: '
', resizing: function (layero) { form.doResize(filter); }, fullScreen:true, success: function (layero) { form.addItems(filter,that.getFormItems(), function () { if(!isEdit) { form.setValues(defaultValueByBtm,filter); }else { form.load(filter,{ url: that.url.controller + that.url.getObjectByOid, backPath:that.backPath, method:'get', params:{ oid:schemaOid } }); } } , {} , { defaultColumnOneRow: 2, labelWidth:180 }); }, yes:function(layero){ if(form.validata(filter)){ var submitValues = form.getValues(filter,true); if(submitValues['backPath'] == "configData."){ $webUtil.showErrorMsg("界面后台路径没有输入值"); return false; } submitValues['genDOFlag'] = 'true'; submitValues['genVOFlag'] = 'true'; submitValues['genDTOFlag'] = 'true'; $webUtil.ajax(isEdit?'PUT':'POST',that.url.controller + (isEdit?that.url.edit:that.url.add),submitValues,function (result) { if(result.success){ $webUtil.showMsgFromResult(result,(isEdit?"配置方案成功":"添加方案成功")); that.refresh(); layer.close(addOrEditIndex); }else{ $webUtil.showErrorMsg(result.msg); } },function (xhr,error) { $webUtil.showErrorMsg("保存代码生成方案出错,可能是服务没有启动"); },that.backPath); } } }); }; this.getFormItems = function(){ var that = this; var packageName = "com.vci"; if(that.packageName){ packageName = that.packageName; } var servicePath = that.servicePath; if(!servicePath){ servicePath = ""; } var user = $webUtil.getCurrentUserId(); if(that.user){ user = that.user; } return [{ field: 'id', text: '业务类型编号', required:true, readOnly:true },{ field: 'name', text: '业务类型名称', required:true },{ field: 'description', text: '方案描述' },{ field:'author', text:'作者', required:true, defaultValue: user },{ field:'fileEncode', text:'文件字符集', defaultValue:'UTF-8' },{ field:'domemo', type:'label', isNewRow:true, text:'数据库实体文件包名,一般业务类型生成时已经包含了;显示对象是指后台返回给前端的对象;数据传输对象是后台用来接收前端传递的数据的对象;必须有中心区', labelWidth:1000 },{ field:'doPackage', text:'数据库实体包', isNewRow:true, defaultValue: packageName + ".model", inputWidth:560 },{ field:'className', text:'数据对象类名称', inputWidth:300 },{ field:'voPackage', text:'显示对象路径', defaultValue: packageName + ".pagemodel", required:true, isNewRow:true, inputWidth:860 },{ field:'dtoPackage', text:'数据传输对象路径', required:true, isNewRow:true, defaultValue: packageName + ".dto", inputWidth:860 },{ field:'controllerPackage', text:'controller的包名', required:true, isNewRow:true, defaultValue: packageName + ".controller", inputWidth:860 },{ field:'controllerRequestMap', text:'controller的请求地址', required:true, useAllWidth:true, inputWidth:860 },{ field:'servicePackage', text:'服务包名', required:true, defaultValue: packageName + ".service", useAllWidth:true, inputWidth:860 },{ field:'mapperPackage', text:'数据库操作包名', required:true, useAllWidth:true, defaultValue: packageName + ".dao", inputWidth:860 },{ field:'mapperXmlPackage', text:'数据库操作实现包名', required:true, defaultValue: packageName + ".dao.impl", },{ field:'jsPackage', text:'界面的路径(到js名)', required:true, inputWidth:450, defaultValue: (that.jsPrefix || '') },{ field:'backPath', text:'界面上的backPath', defaultValue:'configData.compatibility? path:configData.' + servicePath, inputWidth:450 },{ field:'centerLayoutPanelType', type:'combox', comboxKey:'codeGenPanelType1', text:'中心使用的面板', required:true, defaultValue:'table', data:[{key:'table_tree',value:'树表'},{key:'table',value:'表格'},{key:'form',value:'表单'}] },{ field:'centerQueryConfig', text:'中心查询条件', useAllWidth:true , defaultValue:'{id:"编号",name:"名称"}', inputWidth:860 },{ field:'centerButtons', text:'中心按钮', useAllWidth:true , defaultValue:'{ADD:"添加",EDIT:"修改",DEL:"删除",ADVQUERY:"查询",refresh:"刷新"}', inputWidth:860 },{ field:'westLayoutPanelType', type:'combox', comboxKey:'codeGenPanelType', text:'西区使用的面板', isNewRow:true, defaultValue:'tree', data:[{key:"tree",value:'树形'}] },{ field:'useLayoutRegion', type:'switch', //comboxKey:'useLayoutRegion', text:'是否使用西区', defaultValue: "false", //data:[{key:"west",value:'西区'}], //isCheckbox:true, required:true },{ field:'westQueryConfig', text:'西区查询条件', useAllWidth:true , inputWidth:860 },{ field:'westNextRegionParam', text:'上级属性/下个区域联系属性', useAllWidth:true , inputWidth:860 },{ field:'westButtons', text:'西区按钮', useAllWidth:true, inputWidth:860 }]; }; this.productCodeFile = function(oid){ var that = this; if(!oid){ return false; } $webUtil.post(that.url.controller + that.url.productCodeFile,{oid:oid},function(result){ if(result.success){ $webUtil.showMsgFromResult(result,"生成代码成功"); that.refresh(); }else{ $webUtil.showErrorMsg(result.msg); } },function(xhr,error){ $webUtil.showErrorMsg("生成代码失败,可能是服务器没有启动"); },that.backPath); }; this.previewCodeFile = function(oid,text){ var that = this; if(!oid){ return false; } portal.showTabByMenu(that.id + oid,{ id:that.id + oid, text:'查看代码[' + text + "]", url:'USEJS:platform/objectService/OsCodePreview?oid=' + oid }); }; this.downloadCodeFile = function(oid){ var that = this; var iframeId = MD5(oid + $webUtil.getSystemVar($webUtil.systemValueKey.userOid)); $webUtil.fileDownload(that.backPath + that.url.controller + that.url.downloadFile + "?" + TOKEN_KEY + "=" + $webUtil.getToken() + "&downloadUUID=" + iframeId + "&oid=" + oid); }; }; var cs = new Class(); exports(cs.MODELNAME,cs); });