333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
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
}