|
|
|
|
|
define(function (require, exports, module) {
|
|
|
var BaseWindow = require('system/views/pages/window');
|
|
|
require('css!./funcscriptwin.css');
|
|
|
var tpl = require('text!apps/edp/frs/frs004/funcscriptwin.tpl');
|
|
|
var COVERSCRIPT = 'COVER';
|
|
|
|
|
|
function Window(args) {
|
|
|
this.options = {
|
|
|
title: '脚本查看器',
|
|
|
content: tpl,
|
|
|
width: 800,
|
|
|
height: 600,
|
|
|
modal: true,
|
|
|
closed: true,
|
|
|
closable: true,
|
|
|
data: null
|
|
|
};
|
|
|
|
|
|
this.args = args;
|
|
|
BaseWindow.call(this, this.options);
|
|
|
}
|
|
|
|
|
|
inherits(Window, BaseWindow);
|
|
|
|
|
|
Window.prototype.init = function () {
|
|
|
var self = this;
|
|
|
this.setTree();
|
|
|
this.setSqlPreAndSuf();
|
|
|
};
|
|
|
|
|
|
Window.prototype.select = function () {
|
|
|
this.close();
|
|
|
};
|
|
|
|
|
|
Window.prototype.doOp = function (opCode) {
|
|
|
var isHandled = false;
|
|
|
switch (opCode) {
|
|
|
case 'getCoverSql':
|
|
|
this.getSql('0');
|
|
|
break;
|
|
|
case 'getCheckSql':
|
|
|
this.getSql('1');
|
|
|
break;
|
|
|
case 'export':
|
|
|
this.exportScript();
|
|
|
break;
|
|
|
case 'backtosql':
|
|
|
this.showSelectBlock();
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
Window.prototype.refresh = function () {
|
|
|
var self = this;
|
|
|
this.dsMaster.search();
|
|
|
};
|
|
|
|
|
|
Window.prototype.customerize = function ($container) {
|
|
|
var self = this;
|
|
|
this.$txtScript = this.getElement('.txtscript');
|
|
|
this.$scriptNameInput = this.getElement('.edp-frd-script-name-input');
|
|
|
|
|
|
var $getCoverSql = this.getElement('.get-cover-sql');
|
|
|
if ($getCoverSql) {
|
|
|
$getCoverSql.click(function () {
|
|
|
self.doOp('getCoverSql');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
var $getCheckSql = this.getElement('.get-check-sql');
|
|
|
if ($getCheckSql) {
|
|
|
$getCheckSql.click(function () {
|
|
|
self.doOp('getCheckSql');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
var $exportBtn = this.getElement('.btn-export');
|
|
|
if ($exportBtn) {
|
|
|
$exportBtn.click(function () {
|
|
|
self.doOp('export');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
var $closeExport = this.getElement('.btn-close-export');
|
|
|
if ($closeExport) {
|
|
|
$closeExport.click(function () {
|
|
|
self.doOp('backtosql');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
var $closeWindow = this.getElement('.window-close-btn');
|
|
|
if ($closeWindow) {
|
|
|
$closeWindow.click(function () {
|
|
|
self.close();
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
Window.prototype.getSql = function (type) {
|
|
|
this.generateSql(type);
|
|
|
};
|
|
|
|
|
|
Window.prototype.showSql = function () {
|
|
|
var titleElement = this.getElement('.sql-title');
|
|
|
var sqlElement = this.getElement('.sql-content');
|
|
|
var selectBlockElement = this.getElement('.select-data-block');
|
|
|
var showBlockElement = this.getElement('.show-sql-text-block');
|
|
|
titleElement.text(this.sqltitle);
|
|
|
sqlElement.text(this.sqltext);
|
|
|
selectBlockElement.hide();
|
|
|
showBlockElement.show();
|
|
|
};
|
|
|
|
|
|
Window.prototype.showSelectBlock = function () {
|
|
|
var titleElement = this.getElement('.sql-title');
|
|
|
var sqlElement = this.getElement('.sql-content');
|
|
|
var selectBlockElement = this.getElement('.select-data-block');
|
|
|
var showBlockElement = this.getElement('.show-sql-text-block');
|
|
|
titleElement.text('');
|
|
|
sqlElement.text('');
|
|
|
selectBlockElement.show();
|
|
|
showBlockElement.hide();
|
|
|
};
|
|
|
|
|
|
Window.prototype.exportScript = function () {
|
|
|
var self = this,
|
|
|
blob = new Blob(
|
|
|
[this.sqltext],
|
|
|
{ type: "text/plain;charset=" + document.characterSet }
|
|
|
),
|
|
|
url = window.URL.createObjectURL(blob),
|
|
|
download_link = this.getElement('.export-script')[0];
|
|
|
|
|
|
Store.services.fileExport({
|
|
|
filename: this.sqltitle,
|
|
|
content: this.sqltext
|
|
|
}, function (isok, data) {
|
|
|
if (isok) {
|
|
|
download_link.href = Store.host + data.path;
|
|
|
download_link.download = self.sqltitle;
|
|
|
download_link.click();
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
}
|
|
|
})
|
|
|
};
|
|
|
|
|
|
Window.prototype.generateSql = function (type) {
|
|
|
var nodes = this.getSelectedNodes();
|
|
|
if (nodes.length === 0) {
|
|
|
Store.messager.tip('请至少选中一个有效节点');
|
|
|
return;
|
|
|
}
|
|
|
var funccodes = '';
|
|
|
for (var i = 0 ; i < nodes.length; i++) {
|
|
|
funccodes = funccodes + "'" + nodes[i].value + "'";
|
|
|
if (i !== nodes.length - 1) {
|
|
|
funccodes += ',';
|
|
|
}
|
|
|
}
|
|
|
var params = {
|
|
|
plugin: 'etpSqlPlugin',
|
|
|
sync: true,
|
|
|
pluginData: {
|
|
|
funccodes: funccodes,
|
|
|
}
|
|
|
};
|
|
|
var resultData = Store.services.executeplugin(params);
|
|
|
if (resultData.success === false ) {
|
|
|
Store.messager.err('获取数据错误,请稍后重试!');
|
|
|
return;
|
|
|
}
|
|
|
if (resultData.propRows.length === 0 && resultData.langRows.length === 0) {
|
|
|
Store.messager.tip('所选功能无企业模板数据!');
|
|
|
return;
|
|
|
}
|
|
|
this.generateTitle(funccodes, nodes);
|
|
|
let sqltext;
|
|
|
switch (type) {
|
|
|
case '0': //覆盖型
|
|
|
sqltext = this.generateCoverSql(resultData, funccodes, nodes);
|
|
|
break;
|
|
|
case '1': // 校验型
|
|
|
sqltext = this.generateCheckSql(resultData, funccodes, nodes);
|
|
|
break;
|
|
|
}
|
|
|
this.sqltext = sqltext;
|
|
|
this.showSql();
|
|
|
};
|
|
|
|
|
|
Window.prototype.generateTitle = function (funccodes, nodes) {
|
|
|
var tsqltext = '3207_FRS_预置(';
|
|
|
var sqltext = '';
|
|
|
var funcArray = funccodes.split(",");
|
|
|
for (var i = 0, length = funcArray.length; i < length; i++) {
|
|
|
var funccode = funcArray[i].replace(/\'/g, '');
|
|
|
var _funcname = _.where(nodes, { value: funccode })[0].name;
|
|
|
(i !== length - 1) ? tsqltext += funccode + '-' + _funcname + ',' : tsqltext += funccode + '-' + _funcname;
|
|
|
}
|
|
|
tsqltext += ')等功能的企业字典数据脚本.sql';
|
|
|
this.sqltitle = tsqltext;
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 生成funccode-uiobjcode关联对象
|
|
|
* @param {func-uiobj关联行} funcUIReRows
|
|
|
* @param {所有的功能编码} funccodes
|
|
|
*/
|
|
|
Window.prototype.createFuncUIObject = function (funcUIReRows, funccodes) {
|
|
|
var codesArray = funccodes.split(',');
|
|
|
var funcUI = {};
|
|
|
for (var i = 0, length = codesArray.length; i < length; i++) {
|
|
|
var cCode = codesArray[i].replace(/\'/g, '');
|
|
|
funcUI[cCode] = [];
|
|
|
for (var j = 0, jlength = funcUIReRows.length; j < jlength; j++) {
|
|
|
var fcRow = funcUIReRows[j];
|
|
|
if (fcRow.concatcode.indexOf(cCode) > -1) {
|
|
|
funcUI[cCode].push("'" + fcRow.concatcode.substr(cCode.length + 1) + "'");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return funcUI;
|
|
|
};
|
|
|
|
|
|
Window.prototype.generateCheckSql = function (data, funccodes, nodes) {
|
|
|
var funcUI = this.createFuncUIObject(data.funcUIReRows, funccodes);
|
|
|
var sqltext = '/*=============================================*/\n';
|
|
|
sqltext += this.checkPreSql;
|
|
|
for (var key in funcUI) {
|
|
|
var _funcname = _.where(nodes, { value: key})[0].name;
|
|
|
// prop表数据
|
|
|
var temRows = data.propRows.filter(function(item) {
|
|
|
return funcUI[key].indexOf("'" + item.uiobjcode + "'") > -1;
|
|
|
});
|
|
|
if (temRows.length > 0) {
|
|
|
sqltext += '/* 生成' + key + '-' + _funcname + '的企业字典对象明细表(tEtpUIProp)表数据脚本 */\n';
|
|
|
sqltext += this.generateSelectCountSql('tEtpUIProp', funcUI[key]);
|
|
|
data.dataRows = temRows;
|
|
|
sqltext += this.generateInsertSql(data, 'tEtpUIProp');
|
|
|
sqltext += 'Commit;\n' + 'end if;\n';
|
|
|
}
|
|
|
|
|
|
// lang表数据
|
|
|
var temLangRows = data.langRows.filter(function (item) {
|
|
|
return funcUI[key].indexOf("'" + item.uiobjcode + "'") > -1;
|
|
|
});
|
|
|
if (temLangRows.length > 0) {
|
|
|
sqltext += '/* 生成' + key + '-' + _funcname + '的界面对象多语言明细表(tEtpUIPropLang)表数据脚本 */\n';
|
|
|
sqltext += this.generateSelectCountSql('tEtpUIPropLang', funcUI[key]);
|
|
|
data.dataRows = temLangRows;
|
|
|
sqltext += this.generateInsertSql(data, 'tEtpUIPropLang');
|
|
|
sqltext += 'Commit;\n' + 'end if;\n';
|
|
|
}
|
|
|
}
|
|
|
sqltext += 'End;\n' + '/\n';
|
|
|
return sqltext;
|
|
|
};
|
|
|
|
|
|
Window.prototype.generateCoverSql = function (data, funccodes, nodes) {
|
|
|
var sqltext = '/*=============================================*/\n';
|
|
|
var title = '3207_FRS_预置企业模板数据';
|
|
|
sqltext += this.coverPreSql;
|
|
|
sqltext += '/* 生成数据对象:tEtpUIProp-企业字典对象明细表的数据脚本 */\n';
|
|
|
sqltext += this.generateDeleteSql('tEtpUIProp', data.uiobjRows);
|
|
|
data.dataRows = data.propRows;
|
|
|
sqltext += this.generateInsertSql(data, 'tEtpUIProp');
|
|
|
|
|
|
sqltext += '/* 生成数据对象:tEtpUIPropLang-界面对象多语言明细表的数据脚本 */\n';
|
|
|
sqltext += this.generateDeleteSql('tEtpUIPropLang', data.uiobjRows);
|
|
|
data.dataRows = data.langRows;
|
|
|
sqltext += this.generateInsertSql(data, 'tEtpUIPropLang');
|
|
|
sqltext += this.suffixSql;
|
|
|
return sqltext;
|
|
|
};
|
|
|
|
|
|
Window.prototype.generateSelectCountSql = function (uiobjname, uiobjnames) {
|
|
|
var sqltext = "Select count(1) into vi_num from " + uiobjname + " Where uiobjcode in ( " +
|
|
|
uiobjnames + " ) ; " + "if( vi_num = 0 ) then \n";
|
|
|
return sqltext;
|
|
|
}
|
|
|
|
|
|
Window.prototype.generateDeleteSql = function (uiobjname, objRows) {
|
|
|
var uiobjnames = '';
|
|
|
for (var i = 0, length = objRows.length; i < length; i++) {
|
|
|
uiobjnames += "'" + objRows[i].funcobjcode + "'";
|
|
|
i !== length -1 ? uiobjnames += ',' : '';
|
|
|
}
|
|
|
var sqltext = 'Delete from ' + uiobjname + ' where uiobjcode in ( ' + uiobjnames + ' ); \n';
|
|
|
return sqltext;
|
|
|
};
|
|
|
|
|
|
Window.prototype.generateInsertSql = function (data, uiobjname, scriptType) {
|
|
|
var dataRows = data.dataRows;
|
|
|
if (dataRows.length === 0) return '';
|
|
|
var uiobjRows = data.uiobjRows;
|
|
|
var notQuoteRows = uiobjname === 'tEtpUIProp' ? data.propNotQuoteRows : data.langNotQuoteRows;
|
|
|
var propKeys = Object.keys(dataRows[0]);
|
|
|
var cols = propKeys.join(', ');
|
|
|
var sqltext = '';
|
|
|
|
|
|
for (var i = 0, plength = dataRows.length; i < plength; i++) {
|
|
|
var cProw = dataRows[i];
|
|
|
var sqlValues = '';
|
|
|
for (var k = 0, klength = propKeys.length; k < klength; k++) {
|
|
|
var cpkey = propKeys[k];
|
|
|
var value = cProw[cpkey]
|
|
|
if (sqlValues.length > 0) {
|
|
|
sqlValues += ',';
|
|
|
}
|
|
|
var tempArray = notQuoteRows.filter(function (item) {
|
|
|
return item.fieldname.toLowerCase() === cpkey;
|
|
|
});
|
|
|
if (tempArray.length === 0) {
|
|
|
sqlValues += getStrValue(value);
|
|
|
} else {
|
|
|
sqlValues += value;
|
|
|
}
|
|
|
}
|
|
|
sqltext += 'Insert into ' + uiobjname + ' ( ' + cols + ' ) values ( ' + sqlValues + ' ); \n';
|
|
|
}
|
|
|
return sqltext;
|
|
|
};
|
|
|
|
|
|
Window.prototype.generateLangSql = function (data) {
|
|
|
var langRows = data.langRows;
|
|
|
};
|
|
|
|
|
|
Window.prototype.open = function () {
|
|
|
var self = this;
|
|
|
// self.makeScriptName();
|
|
|
BaseWindow.prototype.open.call(self);
|
|
|
};
|
|
|
|
|
|
Window.prototype.setTree = function () {
|
|
|
var self = this,
|
|
|
treeName = 'tree_etp_window';
|
|
|
|
|
|
//注册树组件
|
|
|
var treeArgs = {
|
|
|
actions: {
|
|
|
onClick: function (event, treeNode) {
|
|
|
// self.biz.treeSelected(moduleCode, colName, treeNode);
|
|
|
}
|
|
|
},
|
|
|
opts: {
|
|
|
selectedMulti: true
|
|
|
},
|
|
|
data: this.args.treedata
|
|
|
};
|
|
|
|
|
|
self.register('tree', treeName, treeArgs);
|
|
|
};
|
|
|
|
|
|
Window.prototype.getSelectedNodes = function () {
|
|
|
var ztree = this.widgets["tree_etp_window"].vmodel.$tree;
|
|
|
var nodes = ztree.getSelectedNodes();
|
|
|
var newNodes = [];
|
|
|
while (nodes.length) {
|
|
|
var item = nodes.shift();
|
|
|
if (item.children) {
|
|
|
nodes = nodes.concat(item.children);
|
|
|
} else {
|
|
|
newNodes.push(item);
|
|
|
}
|
|
|
}
|
|
|
return _.uniq(newNodes);
|
|
|
};
|
|
|
|
|
|
Window.prototype.setSqlPreAndSuf = function () {
|
|
|
this.beginPreSql = '/* PUR */\n'+
|
|
|
'/* 日期: */\n'+
|
|
|
'/* 建立者:系统管理员 */\n'+
|
|
|
'/*=============================================*/\n';
|
|
|
this.checkPreSql = this.beginPreSql + 'Declare\n'+ 'vi_num integer;\n' + 'Begin\n';
|
|
|
this.coverPreSql = this.beginPreSql + 'Begin\n';
|
|
|
this.suffixSql = 'Commit;\n'+ 'End;\n'+ '/\n';
|
|
|
}
|
|
|
|
|
|
function getStrValue(value) {
|
|
|
if (value) {
|
|
|
value = value.replace(/'/g, "''");
|
|
|
return "'" + value + "'";
|
|
|
} else {
|
|
|
return value === null ? value : '';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return Window;
|
|
|
});
|