/** * 代码生成器 * @author weidy@2020-07-30 */ layui.define(['layer','element','form','table','util'],function(exports){ var Class = function(){ this.MODELNAME = "platform/objectService/OsCodeGenerator"; this.moduleKey = "OsCodeGenerator"; this.id='OsCodeGenerator'; this.sourceData={}; this.columns = []; 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.buttonIconMap = { SEARCH:'layui-icon-refresh-2', SENIORSEARCH:'layui-icon-query', ADD:'layui-icon-add-1', EDIT:'layui-icon-edit', DELETE:'layui-icon-delete' }; this.panelTypeCombox = [{ "key":"tree", "value":"树形" },{ "key":"table", "value":"表格" },{ "key":"table_tree", "value":"树表" },{ "key":"form", "value":"表单" }]; this.getContent=function(){ var that = this; var html = ""; html = [ '
', '
', '', '
', '
', that.getToolbarHtml(), '
', '', '
', '
' ].join(""); return html; }; this.getToolbarHtml =function(){ var that = this; var html = [ '
', '扫描包', '', '', '
', ].join(""); return html; }; this.init=function(){ var that = this; $webUtil.copyConfig(that,that.moduleKey); 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; }, }); $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.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:200, toolbar: '#toolbar_column_' + that.id }]; } }; this.refresh = function(){ var that = this; layui.table.reload("table_" + that.id); }; 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); } },function (err,xhr){ $webUtil.showErrorMsg("链接服务出错"); },that.backPath); }; 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($webUtil.isNotNull(btmType.implClass) && btmType.implClass.indexOf(".") > -1){ //com.vci.xx.model.yyy的方式 var package = btmType.implClass.substring(0,btmType.implClass.lastIndexOf(".")); defaultValueByBtm['doPackage'] = package; if($webUtil.endWith(package,".model")){ defaultValueByBtm['voPackage'] = package.replace(".model",".pagemodel"); defaultValueByBtm['dtoPackage'] = package.replace(".model",".dto"); defaultValueByBtm['controllerPackage'] = package.replace(".model",".controller"); defaultValueByBtm['servicePackage'] = package.replace(".model",".service"); defaultValueByBtm['mapperPackage'] = package.replace(".model",".mapper"); var className = btmType.implClass.substring(btmType.implClass.lastIndexOf(".") + 1); if($webUtil.endWith(className,"DO")){ className = className.substring(0,className.length-2); } defaultValueByBtm['controllerRequestMap'] = "/" + className.substring(0,1).toLowerCase() + className.substring(1) + "Controller"; } } //看看有没有自参照的类型 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:"启用"}'; } if(("doPackage" in defaultValueByBtm) && defaultValueByBtm['doPackage'] == 'com.vci.frameworkcore.model'){ if(defaultValueByBtm.centerButtons){ defaultValueByBtm.centerButtons = defaultValueByBtm.centerButtons.replace("}",',EXPORT:"导出",IMPORT:"导入"}'); }else{ defaultValueByBtm.centerButtons = '{ADD:"添加",EDIT:"修改",DEL:"删除",ADVQUERY:"查询",refresh:"刷新",EXPORT:"导出",IMPORT:"导入"}'; } } that.editSchema(null,result.obj.id,result.obj.name,defaultValueByBtm); }else{ $webUtil.showErrorMsg(result.msg); } },function(xhr,error){ $webUtil.showErrorMsg("获取业务类型的属性信息出错了,可能是服务没有启动"); },that.backPath); }, 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 },{ field:'tableName', title:'数据库表', width:140 },{ field:'revisionRuleId', title:'版本规则', width:130, templet:function(d){ if(!d.revisionFlag){ return '不控制版本'; }else{ return d.revisionRuleId + ' ' + d.revisionRuleName; } } },{ field:'lifeCycleFlag', title:'生命周期', width:200, templet:function(d){ if(!d.lifeCycleFlag){ return '不控制生命周期'; }else{ return d.lifeCycleId + ' ' + d.lifeCycleName; } } },{ field:'secretFlag', title:'控制密级', width:80, templet:function(d){ return $webUtil.formateBoolean(d.secretFlag); } },{ field:'viewFlag', title:'是否为视图', width:90, templet:function(d){ return $webUtil.formateBoolean(d.viewFlag); } },{ field:'versionRule', title:'版次规则', width:110 }]; } }; 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; } var useLayoutRegion = []; for(var key in submitValues){ if($webUtil.startWith(key,'useLayoutRegion')){ useLayoutRegion.push(key.replace("useLayoutRegion","").replace("[","").replace("]","")); delete submitValues[key]; } } submitValues['useLayoutRegion'] = useLayoutRegion.join((",")); 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; return [{ field: 'id', text: '业务类型编号', required:true, readOnly:true },{ field: 'name', text: '业务类型名称', required:true },{ field: 'description', text: '方案描述' },{ field:'author', text:'作者', required:true },{ field:'fileEncode', text:'文件字符集', defaultValue:'UTF-8' },{ field:'domemo', type:'label', isNewRow:true, text:'数据库实体文件包名,一般业务类型生成时已经包含了;显示对象是指后台返回给前端的对象;数据传输对象是后台用来接收前端传递的数据的对象;必须有中心区', labelWidth:1000 },{ field:'doPackage', text:'数据库实体包', isNewRow:true, inputWidth:860 },{ field:'voPackage', text:'显示对象路径', required:true, isNewRow:true, inputWidth:860 },{ field:'dtoPackage', text:'数据传输对象路径', required:true, isNewRow:true, inputWidth:860 },{ field:'controllerPackage', text:'controller的包名', required:true, isNewRow:true, inputWidth:860 },{ field:'controllerRequestMap', text:'controller的请求地址', required:true, useAllWidth:true, inputWidth:860 },{ field:'servicePackage', text:'服务包名', required:true, useAllWidth:true, inputWidth:860 },{ field:'mapperPackage', text:'数据库操作包名', required:true, useAllWidth:true, inputWidth:860 },{ field:'mapperXmlPackage', text:'mybatis的xml位置', required:true, defaultValue:'mybatis' },{ field:'jsPackage', text:'界面的路径(到js名)', required:true, 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:'backPath', text:'界面上的backPath', defaultValue:'configData.', inputWidth:450 },{ 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:'combox', comboxKey:'useLayoutRegion', text:'是否使用西区', data:[{key:"west",value:'西区'}], isCheckbox:true, required:true, inputWidth:450 },{ 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); });