import BaseService from "../baseService";
|
import { SysMvcTableInfo } from "../../entity/sys/core/sysMvcTableInfo";
|
import { SysMvcTableColumn } from "../../entity/sys/core/sysMvcTableColumn";
|
import { ResultInfo } from "../../public/commonInterface";
|
|
interface tableParams {
|
dbServer: string;
|
projectName: string;
|
tableName: string;
|
cnName: string;
|
enName: string;
|
folderName: string;
|
parentId: number;
|
table_Id: number;
|
}
|
|
/**
|
* 菜单管理
|
*/
|
export default class SysMvcService extends BaseService {
|
//#region 属性
|
/// <summary>
|
/// 参数集合
|
/// </summary>
|
private _params: tableParams;
|
public set params(val) {
|
this._params = val;
|
}
|
public get params() {
|
return this._params;
|
}
|
//#endregion
|
|
//#region generateTableColumns
|
/**
|
* 提取字段
|
*/
|
public async generateTableColumns(): Promise<ResultInfo> {
|
if (!this.params.tableName) {
|
this.info.result = false;
|
this.info.msg = "参数表名不存在";
|
return this.info;
|
}
|
|
//获得Sys_MvcTableInfo主键值
|
let tableInfo = await this.getTableInfo();
|
this.params.table_Id = tableInfo.table_Id;
|
|
//获得新字段信息
|
let columnInfoList = await this.getDBColumnInfo();
|
let index = 0;
|
|
for (let columnInfo of columnInfoList) {
|
let isManagerTable = 1;
|
let isManagerDataSet = 1;
|
let isReadTable = 1;
|
let isReadDataset = 0;
|
let isEditDataSet = 1;
|
let formatter = "";
|
let columnWidth = 80;
|
let dropDown_Id = null;
|
let columnName = columnInfo.columnName;
|
|
//#region 获得字段宽度
|
let dbDataType = columnInfo.dataType;
|
dbDataType = dbDataType.toLocaleLowerCase();
|
switch (dbDataType) {
|
case "date":
|
columnWidth = 80;
|
break;
|
case "datetime":
|
case "smalldatetime":
|
case "timestamp":
|
columnWidth = 130;
|
break;
|
}
|
if (columnName.endsWith("code")) {
|
columnWidth = 110;
|
//isReadDataset = 1;
|
}
|
//#endregion
|
|
//#region 管理只读/数据只读/数据集
|
let dataType = dbDataType;
|
columnName = this.ctx.helper.caseStyle(columnName);
|
if (columnName.endsWith("_Id") || columnName.endsWith("ID") || columnName.endsWith("IDs")) {
|
isReadTable = 1;
|
isReadDataset = 1;
|
isManagerTable = 0;
|
}
|
if ("creator,createDate,modifier,modifyDate,deleteBy".indexOf(columnName) >= 0) {
|
isReadDataset = 1;
|
|
isManagerTable = 0;
|
isManagerDataSet = 1;
|
isEditDataSet = 1;
|
}
|
if ("auditor,auditing,auditDate".indexOf(columnName) >= 0) {
|
isReadDataset = 1;
|
}
|
//#endregion
|
|
//#region 下拉框默认值
|
if (columnName == "expressCorpName") {
|
dropDown_Id = 568;
|
} else if (columnName == "userTrueName") {
|
dropDown_Id = 22;
|
} else if (columnName == "auditing") {
|
dropDown_Id = 21;
|
} else if (columnName == "accountName") {
|
dropDown_Id = 28;
|
} else if (columnName == "enable") {
|
dropDown_Id = 20;
|
} else if (columnName == "storageName") {
|
dropDown_Id = 31;
|
} else if (columnName == "deptName") {
|
dropDown_Id = 23;
|
} else if (columnName == "providerShortName") {
|
dropDown_Id = 33;
|
} else if (columnName == "consignorName") {
|
dropDown_Id = 797;
|
}
|
//#endregion
|
|
//#region 默认值
|
let defaultValue = columnInfo.defaultValue;
|
if (defaultValue && typeof defaultValue == "string") {
|
defaultValue = defaultValue.replace("(getdate())", "{currentDate}").replace("(", "").replace(")", "").replace("'", "").replace("N", "");
|
} else if (columnName == "user_Id") {
|
defaultValue = "{userInfo.user_Id}";
|
} else if (columnName == "userTrueName") {
|
defaultValue = "{serInfo.userTrueName}";
|
} else if (columnName == "createID") {
|
defaultValue = "{uerInfo.user_Id}";
|
}
|
//#endregion
|
|
let _colInfo = await this.dbRead.findOne(SysMvcTableColumn, {
|
table_Id: this.params.table_Id,
|
columnName: columnName
|
});
|
|
if (!_colInfo) {
|
_colInfo = new SysMvcTableColumn();
|
} else {
|
// 提取的字段备注为空默认原始值
|
if (!columnInfo.columnComment) {
|
columnInfo.columnComment = _colInfo.columnComment;
|
}
|
}
|
_colInfo = Object.assign(_colInfo, columnInfo);
|
_colInfo.defaultValue = defaultValue;
|
_colInfo.isManagerDataSet = isManagerDataSet;
|
_colInfo.isManagerTable = isManagerTable;
|
_colInfo.isReadDataset = isReadDataset;
|
_colInfo.isReadTable = isReadTable;
|
_colInfo.isEditDataSet = isEditDataSet;
|
_colInfo.formatter = formatter;
|
_colInfo.columnWidth = columnWidth;
|
_colInfo.dropDown_Id = dropDown_Id;
|
_colInfo.dataType = dataType;
|
_colInfo.table_Id = this.params.table_Id;
|
_colInfo.nullable = columnInfo.nullable;
|
_colInfo.resizable = 1;
|
_colInfo.sortable = 1;
|
_colInfo.colspan = 0;
|
_colInfo.rowspan = 0;
|
_colInfo.editType = "textEditor";
|
if ("createID,creator,createDate,modifyID,modifier,modifyDate".indexOf(columnName) >= 0) {
|
_colInfo.editType = "label";
|
}
|
_colInfo.editNameAttribute = 'class="control-label"';
|
_colInfo.editValueAttribute = 'class="input-block-level"';
|
_colInfo.isViewDataSet = _colInfo.isEditDataSet;
|
_colInfo.viewNameAttribute = 'class="ViewName"';
|
_colInfo.viewValueAttribute = 'class="ViewValue"';
|
|
if (index == 0) {
|
tableInfo.keyIDs = columnName;
|
tableInfo.sortName = columnName.endsWith("List_Id") ? columnName : columnName + " DESC";
|
_colInfo.fieldAttribute = "Key";
|
} else if (index == 1) {
|
tableInfo.linkColumn = columnName;
|
tableInfo.queryKeys = columnName;
|
//tableInfo.CodeRegular = columnName;
|
}
|
|
await this.dbWrite.save(_colInfo);
|
index++;
|
}
|
|
this.info.result = true;
|
this.info.data = tableInfo;
|
this.info.msg = "共提取到" + index + "字段";
|
return this.info;
|
}
|
//#endregion
|
|
//#region getTableInfo 生成TableList且获得表ID
|
private async getTableInfo() {
|
let keyIDs = "";
|
let keyIDArray = this.params.tableName.split("_");
|
keyIDs = keyIDArray[keyIDArray.length - 1] + "_Id";
|
keyIDs = this.ctx.helper.caseStyle(keyIDs);
|
|
let tableInfo = await this.dbRead.findOne(SysMvcTableInfo, {
|
tableView: this.params.tableName
|
});
|
if (tableInfo == null) {
|
tableInfo = new SysMvcTableInfo();
|
|
tableInfo.tableName = this.params.tableName;
|
tableInfo.tableView = this.params.tableName;
|
tableInfo.cnName = this.params.cnName;
|
tableInfo.enName = this.params.enName;
|
tableInfo.dBServer = this.params.dbServer;
|
tableInfo.dBServerReadOnly = this.params.dbServer;
|
tableInfo.parentId = this.params.parentId;
|
tableInfo.keyIDs = keyIDs;
|
tableInfo.orderNo = 0;
|
|
let namesplaces = this.params.projectName.split(".");
|
let moduleName = namesplaces[namesplaces.length - 1];
|
tableInfo.namespace = this.params.projectName;
|
tableInfo.folderName = this.params.folderName;
|
|
//主题
|
tableInfo.theme = "BootstrapMetro";
|
tableInfo.editorMode = "任意模式";
|
|
//管理页面
|
tableInfo.dataTableType = 7; // 简洁查询
|
tableInfo.dataTablePath = "/Template/{theme}/SearcherSimple.html";
|
tableInfo.dataTableSavePath = "/Views/" + moduleName + "/{folder}/Pub/{theme}/" + this.params.tableName + "Searcher.cshtml";
|
|
//编辑页面
|
tableInfo.editorLayout = null;
|
tableInfo.editorType = 1; // 单表编辑
|
tableInfo.editorPath = "/Template/{theme}/EditorSingle.html";
|
tableInfo.editorSavePath = "/Views/" + moduleName + "/{folder}/Pub/{theme}/" + this.params.tableName + "Editor.cshtml";
|
tableInfo.editorTitle = this.params.cnName + "编辑";
|
tableInfo.editorSubTitle = this.params.cnName + " - 基础信息";
|
|
tableInfo.editorEnTitle = this.params.enName + " Edit";
|
tableInfo.editorEnSubTitle = this.params.enName + " - Basic Information";
|
|
//视图页面
|
tableInfo.viewLayout = null;
|
tableInfo.viewType = null; //(int)eViewType.Single;
|
tableInfo.viewPath = null; //"/Template/{theme}/ViewerSingle.html";
|
tableInfo.viewSavePath = "/Views/" + moduleName + "/{folder}/Pub/{theme}/" + this.params.tableName + "Viewer.cshtml";
|
|
//领域模型
|
tableInfo.domainModelType = 1; // 标准视图
|
tableInfo.domainModelPath = "/Template/DomainModel.html";
|
tableInfo.domainModelSavePath = "../" + this.params.projectName + "/DomainModels/{folder}/" + this.params.tableName + "Model.cs";
|
|
//Mobile管理页面
|
tableInfo.mobileDataTableType = 1; // 单表管理
|
tableInfo.mobileDataTablePath = "/Template/{theme}/ManagerSingle.html";
|
tableInfo.mobileDataTableSavePath = "/Views/" + moduleName + "/{folder}/Pub/{theme}/Mobile" + this.params.tableName + "DataTable.cshtml";
|
|
//Mobile编辑页面
|
tableInfo.mobileEditorType = 1;
|
tableInfo.mobileEditorPath = "/Template/{theme}/EditorSingle.html"; // 单表编辑
|
tableInfo.mobileEditorSavePath = "/Views/" + moduleName + "/{folder}/Pub/{theme}/Mobile" + this.params.tableName + "Editor.cshtml";
|
|
//Mobile视图页面
|
tableInfo.mobileViewType = null; //(int)eViewType.Single;
|
tableInfo.mobileViewPath = null; //"/Template/{theme}/ViewerSingle.html";
|
tableInfo.mobileViewSavePath = "/Views/" + moduleName + "/{folder}/Pub/{theme}/Mobile" + this.params.tableName + "Viewer.cshtml";
|
|
tableInfo.isColumnAuth = 0;
|
tableInfo.isDisplay = 1;
|
tableInfo.isDisplayPager = 1;
|
tableInfo.isEnableView = 0;
|
tableInfo.isFlagModify = 1;
|
tableInfo.isHScroll = 1;
|
tableInfo.isVScroll = 1;
|
tableInfo.isPhysicsDelete = 1;
|
tableInfo.isGridOrder = 0;
|
tableInfo.isReadOnlyDataset = 0;
|
tableInfo.isReadOnlyDataTable = 1;
|
tableInfo.isShowFooter = 0;
|
tableInfo.isSumAll = 0;
|
tableInfo.isMapDBServer = 0;
|
tableInfo.remoteSort = this.params.tableName.endsWith("List") ? 0 : 1;
|
|
//表格
|
tableInfo.pageSize = 30;
|
tableInfo.fitColumns = 0;
|
tableInfo.striped = 1;
|
tableInfo.url = "/" + moduleName.toLocaleLowerCase() + "/data/ManagerData";
|
tableInfo.loadMsg = '@(UserHelper.UserInfo.isEnglish ? "The data being processed, waiting..." : "数据正在处理,稍等...")';
|
tableInfo.pagination = 1;
|
tableInfo.rownumbers = 1;
|
tableInfo.singleSelect = 0;
|
tableInfo.nowrap = 1;
|
tableInfo.pageNumber = 1;
|
tableInfo.pageList = "10,20,30,50,80,100,200,500,1000";
|
tableInfo.sortName = `{"${keyIDs}": "DESC"}`;
|
//tableList.SortOrder = "";
|
tableInfo.dataGridHeight = 350;
|
|
tableInfo.linkColumn = this.ctx.helper.caseStyle(keyIDArray[keyIDArray.length - 1] + "Code");
|
//tableInfo.CodeRegular = tableInfo.LinkColumn;
|
tableInfo.queryKeys = tableInfo.linkColumn;
|
|
//编辑
|
tableInfo.addUrl = "/sys/data/initdata";
|
tableInfo.editUrl = "/" + moduleName.toLocaleLowerCase() + "/data/editdata";
|
tableInfo.saveUrl = "/" + moduleName.toLocaleLowerCase() + "/data/saveeditdata";
|
tableInfo.viewUrl = "/" + moduleName.toLocaleLowerCase() + "/data/viewerdata";
|
|
//视图
|
if (tableInfo.tableView.endsWith("List")) {
|
tableInfo.viewerTitle = tableInfo.cnName.replace("List", "") + "明细";
|
tableInfo.viewerEnTitle = tableInfo.cnName.replace("List", "") + " Details";
|
}
|
|
await this.dbWrite.save(tableInfo);
|
}
|
return tableInfo;
|
}
|
//#endregion
|
|
//#region getDBColumnInfo
|
private async getDBColumnInfo() {
|
let sql = `
|
SELECT Sysobjects.name AS tableView, syscolumns.name AS columnName,
|
systypes.name AS dataType, syscolumns.length as dataTypeLength,
|
sys.extended_properties.[value] AS columnComment, syscomments.text as
|
defaultValue,syscolumns.isnullable as nullable, syscolumns.colid,syscolumns.scale
|
FROM Syscolumns
|
INNER JOIN Systypes
|
ON Syscolumns.xtype = systypes.xtype
|
LEFT JOIN Sysobjects ON Syscolumns.id = Sysobjects.id
|
LEFT OUTER JOIN sys.extended_properties ON
|
(
|
sys.extended_properties.minor_id = syscolumns.colid
|
AND sys.extended_properties.major_id = syscolumns.id
|
)
|
LEFT OUTER JOIN syscomments ON syscolumns.cdefault = syscomments.id
|
WHERE syscolumns.id IN
|
(
|
SELECT id FROM SYSOBJECTS WHERE xtype in('U', 'V')
|
) AND (systypes.name <> 'sysname')
|
AND (Sysobjects.name ='${this.params.tableName}')
|
and systypes.name!='mail'
|
ORDER BY syscolumns.colid;`;
|
|
let info = await this.dbRead.query(sql);
|
|
return info;
|
}
|
|
//#endregion
|
}
|