|
@@ -1,10 +1,23 @@
|
|
|
import { graphStateEnum } from "./graphStateEnum";
|
|
|
import { sysGraphHttpUtils } from "@/utils/http/sysGraphHttpUtils";
|
|
|
import { logicConfig } from "@/logicConfig";
|
|
|
-import moment, { Moment } from 'moment';
|
|
|
+import moment from 'moment';
|
|
|
|
|
|
export class sysGraphController {
|
|
|
private static sysGraphHttpUtilsInstance = new sysGraphHttpUtils();
|
|
|
+ //key为系统类型编码,值为 系统图类型 > 模板数据 的二级结构数组
|
|
|
+ private static _tempTemplateObj = {};
|
|
|
+ //三级数组 专业>系统类型>系统实例
|
|
|
+ private static zhuanyeArr = [];
|
|
|
+
|
|
|
+
|
|
|
+ //根据状态编码转状态名称
|
|
|
+ static getStateNameByCode(stateCode: string) {
|
|
|
+ return stateCode == graphStateEnum.Draft ? '草稿' :
|
|
|
+ stateCode == graphStateEnum.Publish ? '上架' :
|
|
|
+ stateCode == graphStateEnum.Recyle ? '回收站' : '';
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询系统图列表
|
|
|
* @param grpphName 系统图名称
|
|
@@ -14,32 +27,31 @@ export class sysGraphController {
|
|
|
var resultObj = await this.sysGraphHttpUtilsInstance.postRequest('/diagram/getDiagrams', { name: grpphName });
|
|
|
if (resultObj.result != logicConfig.resultObj.success)
|
|
|
console.error(resultObj.reason);
|
|
|
+
|
|
|
+ //key为系统类型编码,值为系统类型数据
|
|
|
+ var _tempSystemTypeObj = {};
|
|
|
var newDataArr = [];
|
|
|
- var dataArr = resultObj.data || [];
|
|
|
- console.log(JSON.parse(JSON.stringify(dataArr)));
|
|
|
+ var dataArr = (resultObj.data || []).filter(_c => {
|
|
|
+ return (_c.extraProps || {}).state != graphStateEnum.Recyle;
|
|
|
+ });
|
|
|
dataArr.sort(function (a, b) {
|
|
|
return b.createTime - a.createTime;
|
|
|
});
|
|
|
|
|
|
|
|
|
//取得专业>系统类型>系统实例 以和系统图列表中的系统类型编码 对应以获取系统类型名称
|
|
|
- var url2 = '/diagram/major/system/instance';
|
|
|
- var zhuanyeObj = await this.sysGraphHttpUtilsInstance.postRequest(url2, {});
|
|
|
- var zhuanyeArr = zhuanyeObj.data || [];
|
|
|
+ if (this.zhuanyeArr.length == 0) {
|
|
|
+ var url2 = '/diagram/major/system/instance';
|
|
|
+ var zhuanyeObj = await this.sysGraphHttpUtilsInstance.postRequest(url2, {});
|
|
|
+ this.zhuanyeArr = zhuanyeObj.data || [];
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- //key为系统类型编码,值为系统类型数据
|
|
|
- var _tempSystemTypeObj = {};
|
|
|
- //key为系统类型编码,值为 系统图类型 > 模板数据 的二级结构数组
|
|
|
- var _tempTemplateObj = {};
|
|
|
-
|
|
|
for (let i = 0; i < dataArr.length; i++) {
|
|
|
let _c = dataArr[i];
|
|
|
let extraProps = _c.extraProps;
|
|
|
//图状态(Draft: 未发布, WaitCheck: 待审核, Checked: 审核完成, Recyle: 回收站, Publish: 发布)
|
|
|
- let stateName = extraProps.state == graphStateEnum.Draft ? '草稿' :
|
|
|
- extraProps.state == graphStateEnum.Publish ? '上架' :
|
|
|
- extraProps.state == graphStateEnum.Recyle ? '下架' : '';
|
|
|
+ let stateName = this.getStateNameByCode(extraProps.state);
|
|
|
|
|
|
//获取系统类型名称
|
|
|
let systemTypeName = (_tempSystemTypeObj[_c.system] || {}).aliasName;
|
|
@@ -49,8 +61,8 @@ export class sysGraphController {
|
|
|
}
|
|
|
|
|
|
//获取模版名称
|
|
|
- let _templateObj = await getTemplateBySysTypeCode(_c.system, _c.templateId);
|
|
|
- let templateName = (_templateObj || {}).name || '';
|
|
|
+ let _templateObj = await this.getTemplateGraphTypeBySysTypeCode(_c.system, _c.templateId);
|
|
|
+ let templateName = ((_templateObj || {}).template || {}).name || '';
|
|
|
|
|
|
//格式化日期时间
|
|
|
let momentInstance = moment(_c.createTime);
|
|
@@ -73,9 +85,9 @@ export class sysGraphController {
|
|
|
|
|
|
|
|
|
function getSystemTypeByCode(systemTypeCode: string) {
|
|
|
- for (let i = 0; i < zhuanyeArr.length; i++) {
|
|
|
+ for (let i = 0; i < sysGraphController.zhuanyeArr.length; i++) {
|
|
|
//专业
|
|
|
- let zhuanye = zhuanyeArr[i];
|
|
|
+ let zhuanye = sysGraphController.zhuanyeArr[i];
|
|
|
//系统类型数组
|
|
|
let systemTypeArr = zhuanye.children || [];
|
|
|
let isFind = false;
|
|
@@ -92,34 +104,44 @@ export class sysGraphController {
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
+ }
|
|
|
|
|
|
- async function getTemplateBySysTypeCode(sysTypeCode: string, templateId: string) {
|
|
|
- var dataArr = _tempTemplateObj[sysTypeCode];
|
|
|
+ /**
|
|
|
+ * 根据系统类型查询系统图模板和系统图类型,数据结构:系统图类型 -> 系统图模版
|
|
|
+ * @param sysTypeCode 系统类型编码
|
|
|
+ * @param templateId 模版ID
|
|
|
+ * @return {template:{id:'',name:''},graphType:{id:'',name:''}}
|
|
|
+ */
|
|
|
+ static async getTemplateGraphTypeBySysTypeCode(sysTypeCode: string, templateId: string) {
|
|
|
+ var dataArr = this._tempTemplateObj[sysTypeCode];
|
|
|
|
|
|
- if (!dataArr) {
|
|
|
- let url = '/diagram/systemType/template';
|
|
|
- let resultObj = await sysGraphController.sysGraphHttpUtilsInstance.postRequest(url, { system: sysTypeCode });
|
|
|
- dataArr = resultObj.data || [];
|
|
|
- }
|
|
|
+ if (!dataArr) {
|
|
|
+ let url = '/diagram/systemType/template';
|
|
|
+ let resultObj = await sysGraphController.sysGraphHttpUtilsInstance.postRequest(url, { system: sysTypeCode });
|
|
|
+ dataArr = resultObj.data || [];
|
|
|
+ }
|
|
|
+ this._tempTemplateObj[sysTypeCode] = dataArr;
|
|
|
|
|
|
- for (let i = 0; i < dataArr.length; i++) {
|
|
|
- //_sysGraphType为系统图类型
|
|
|
- let sysGraphType = dataArr[i];
|
|
|
- //模板数组
|
|
|
- let templateArr = sysGraphType.children || [];
|
|
|
- let isFind = false;
|
|
|
- for (let j = 0; j < templateArr.length; j++) {
|
|
|
- //模板
|
|
|
- let template = templateArr[j];
|
|
|
- if (template.id == templateId) {
|
|
|
- return template;
|
|
|
- }
|
|
|
+ for (let i = 0; i < dataArr.length; i++) {
|
|
|
+ //_sysGraphType为系统图类型
|
|
|
+ let sysGraphType = dataArr[i];
|
|
|
+ //模板数组
|
|
|
+ let templateArr = sysGraphType.children || [];
|
|
|
+ for (let j = 0; j < templateArr.length; j++) {
|
|
|
+ //模板
|
|
|
+ let template = templateArr[j];
|
|
|
+ if (template.id == templateId) {
|
|
|
+ return {
|
|
|
+ template: { id: template.id, name: template.name },
|
|
|
+ graphType: { id: sysGraphType.id, name: sysGraphType.name }
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 根据项目查询该项目下的专业>系统类型>系统实例
|
|
|
* @param projectId 项目ID
|
|
@@ -131,6 +153,7 @@ export class sysGraphController {
|
|
|
if (resultObj.result != logicConfig.resultObj.success)
|
|
|
console.error(resultObj.reason);
|
|
|
var dataArr = resultObj.data || [];
|
|
|
+ this.zhuanyeArr = dataArr;
|
|
|
var newDataArr = [];
|
|
|
|
|
|
dataArr.forEach(_c => {
|
|
@@ -189,7 +212,7 @@ export class sysGraphController {
|
|
|
var url = '/diagram/newDiagram';
|
|
|
var resultObj = await this.sysGraphHttpUtilsInstance.postRequest(url, _paramObj);
|
|
|
if (resultObj.result != logicConfig.resultObj.success) {
|
|
|
- console.error(resultObj.reason);
|
|
|
+ resultObj.reason = '新建系统图失败:' + resultObj.reason;
|
|
|
return resultObj;
|
|
|
}
|
|
|
|
|
@@ -201,17 +224,36 @@ export class sysGraphController {
|
|
|
var loadDataUrl = '/diagram/loadData';
|
|
|
var loadResultObj = await this.sysGraphHttpUtilsInstance.postRequest(loadDataUrl, { id: dataObj.id });
|
|
|
if (loadResultObj.result != logicConfig.resultObj.success) {
|
|
|
- return { result: logicConfig.resultObj.failure, reason: '加载模板数据失败,原因:' + loadResultObj.reason };
|
|
|
+ loadResultObj.reason = '加载模板数据失败:' + loadResultObj.reason;
|
|
|
+ return loadResultObj;
|
|
|
+ }
|
|
|
+
|
|
|
+ //加载数据成功后保存数据
|
|
|
+ var saveResultObj = await this.saveSysGraph(loadResultObj.data);
|
|
|
+ if (saveResultObj.result != logicConfig.resultObj.success) {
|
|
|
+ saveResultObj.reason = '保存系统图数据失败:' + saveResultObj.reason;
|
|
|
+ return saveResultObj;
|
|
|
}
|
|
|
- console.log(JSON.stringify(loadResultObj.data));
|
|
|
+
|
|
|
+ //因为保存数据成功返回的data里的数据不全,所以返回加载数据成功后的数据给页面
|
|
|
return loadResultObj;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 保存系统图数据
|
|
|
+ * @param _paramObj 参见后台loadData接口的返回
|
|
|
+ */
|
|
|
+ static async saveSysGraph(_paramObj: any) {
|
|
|
+ var saveUrl = '/diagram/newDiagram';
|
|
|
+ var saveResultObj = await this.sysGraphHttpUtilsInstance.postRequest(saveUrl, _paramObj);
|
|
|
+ return saveResultObj;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据系统图ID查询系统图信息
|
|
|
* @param id 系统图ID
|
|
|
*/
|
|
|
- static async getDiagramById(id: string) {
|
|
|
+ static async getDiagramById(id: string, groupCode: string, projectId: string) {
|
|
|
var url = '/diagram/getDiagram?diagramId=' + id;
|
|
|
var resultObj = await this.sysGraphHttpUtilsInstance.getRequest(url, {});
|
|
|
if (resultObj.result != logicConfig.resultObj.success) {
|
|
@@ -223,8 +265,55 @@ export class sysGraphController {
|
|
|
if (!dataObj.id)
|
|
|
return { result: logicConfig.resultObj.failure, reason: '缺少系统图ID' };
|
|
|
|
|
|
+ //取得专业>系统类型>系统实例 以和系统图列表中的系统类型编码 对应以获取系统实例名称
|
|
|
+ if (this.zhuanyeArr.length == 0) {
|
|
|
+ var url2 = '/diagram/major/system/instance?groupCode=' + groupCode + '&projectId=' + projectId;
|
|
|
+ var zhuanyeObj = await this.sysGraphHttpUtilsInstance.postRequest(url2, {});
|
|
|
+ this.zhuanyeArr = zhuanyeObj.data || [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取系统实例名称
|
|
|
+ var _systemInstance = getSystemInstanceByCode(resultObj.data.systemId);
|
|
|
+ console.log(_systemInstance);
|
|
|
+ resultObj.data.systemInstanceName = _systemInstance.name || '';
|
|
|
+
|
|
|
+
|
|
|
+ //获取系统图类型和系统图模版
|
|
|
+ var _temoObj = await this.getTemplateGraphTypeBySysTypeCode(resultObj.data.system, resultObj.data.templateId);
|
|
|
+ resultObj.data.graphTypeName = ((_temoObj || {}).graphType || {}).name;
|
|
|
+ resultObj.data.templateName = ((_temoObj || {}).template || {}).name;
|
|
|
+
|
|
|
+ //状态名称
|
|
|
+ resultObj.data.stateName = this.getStateNameByCode(resultObj.data.extraProps.state);
|
|
|
+
|
|
|
|
|
|
return resultObj;
|
|
|
+
|
|
|
+ //获取系统实例信息
|
|
|
+ function getSystemInstanceByCode(systemInstanceId: string) {
|
|
|
+ for (let i = 0; i < sysGraphController.zhuanyeArr.length; i++) {
|
|
|
+ //专业
|
|
|
+ let zhuanye = sysGraphController.zhuanyeArr[i];
|
|
|
+ //系统类型数组
|
|
|
+ let systemTypeArr = zhuanye.children || [];
|
|
|
+ let isFind = false;
|
|
|
+ for (let j = 0; j < systemTypeArr.length; j++) {
|
|
|
+ //系统类型
|
|
|
+ let systemType = systemTypeArr[j];
|
|
|
+ //系统实例数组
|
|
|
+ let systemInstanceArr = systemType.children || [];
|
|
|
+ for (let k = 0; k < systemInstanceArr.length; k++) {
|
|
|
+ //系统实例
|
|
|
+ let systemInstance = systemInstanceArr[k];
|
|
|
+ if (systemInstance.id == systemInstanceId)
|
|
|
+ return systemInstance;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isFind)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
return {
|
|
|
result: 'success',
|
|
|
data: {
|
|
@@ -10380,4 +10469,28 @@ export class sysGraphController {
|
|
|
return resultObj;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 打开系统图新增、预览、编辑页面
|
|
|
+ * @param state 打开新页面时的状态,0 预览; 1 编辑; 2 新建
|
|
|
+ * @param diagramId 系统图ID
|
|
|
+ * @param groupCode 集团编码
|
|
|
+ * @param projectId 项目ID
|
|
|
+ * @param projectName 项目名称
|
|
|
+ * @param baseUrl 根路径
|
|
|
+ * @param isOpenTarget 是否打开新页面
|
|
|
+ */
|
|
|
+ static openGraphPage(state: number, diagramId: string, groupCode: string, projectId: string, projectName: string, baseUrl: string, isOpenTarget: boolean) {
|
|
|
+ var url = "/" +
|
|
|
+ baseUrl +
|
|
|
+ logicConfig.routerNameConfig.systemGraphEditName +
|
|
|
+ "?ost=" +
|
|
|
+ state +
|
|
|
+ "&did=" +
|
|
|
+ (diagramId || "") +
|
|
|
+ '&gc=' + (groupCode || '') +
|
|
|
+ '&pri=' + (projectId || '') +
|
|
|
+ '&prn=' + encodeURIComponent(projectName || '');
|
|
|
+ isOpenTarget === true ? window.open(url) : window.location.href = url;
|
|
|
+ }
|
|
|
+
|
|
|
}
|