From 3dc5e2995cdadd7759605c67cdd35eb0516315af Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Thu, 2 Nov 2023 16:31:45 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E8=B5=84=E6=BA=90=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=BA=E6=9E=84id=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/latestMetadata/index.js | 79 +++-- .../controllers/resourceConsumption/index.js | 14 +- api/app/lib/models/resource_consumption.js | 281 +++++++++--------- .../03_alter_t_resource_consumption.sql | 4 + .../containers/databasesTable.js | 4 +- .../containers/filesTable.js | 2 +- .../containers/restapisTable.js | 2 +- .../resourceConsumption/containers/approve.js | 10 +- 8 files changed, 225 insertions(+), 171 deletions(-) create mode 100644 scripts/0.0.14/03_alter_t_resource_consumption.sql diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index 49625f8..f987aa5 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -3,7 +3,7 @@ const moment = require("moment/moment"); //获取资源目录 -async function getResourceCatalog (ctx) { +async function getResourceCatalog(ctx) { try { const models = ctx.fs.dc.models; const rslt = await models.ResourceCatalog.findAll({ @@ -20,7 +20,7 @@ async function getResourceCatalog (ctx) { } } //新建资源目录 -async function postResourceCatalog (ctx) { +async function postResourceCatalog(ctx) { try { const { name, code } = ctx.request.body; const models = ctx.fs.dc.models; @@ -49,7 +49,7 @@ async function postResourceCatalog (ctx) { } } //修改资源目录 -async function putResourceCatalog (ctx) { +async function putResourceCatalog(ctx) { try { const { id } = ctx.params; const { name, code, description } = ctx.request.body; @@ -78,7 +78,7 @@ async function putResourceCatalog (ctx) { } } //删除资源目录 -async function delResourceCatalog (ctx) { +async function delResourceCatalog(ctx) { const transaction = await ctx.fs.dc.orm.transaction(); try { const models = ctx.fs.dc.models; @@ -117,7 +117,7 @@ async function delResourceCatalog (ctx) { } } //获取库表元数据列表 -async function getMetadataDatabases (ctx) { +async function getMetadataDatabases(ctx) { try { const models = ctx.fs.dc.models; const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', id = null, resourceId } = ctx.query; @@ -169,7 +169,7 @@ async function getMetadataDatabases (ctx) { } } //获取文件元数据列表 -async function getMetadataFiles (ctx) { +async function getMetadataFiles(ctx) { try { const models = ctx.fs.dc.models; const { catalog, limit, offset, keywords, orderBy = 'updateAt', orderDirection = 'desc', resourceId } = ctx.query; @@ -214,7 +214,7 @@ async function getMetadataFiles (ctx) { } } //获取接口元数据列表 -async function getMetadataRestapis (ctx) { +async function getMetadataRestapis(ctx) { try { const models = ctx.fs.dc.models; const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', resourceId } = ctx.query; @@ -257,7 +257,7 @@ async function getMetadataRestapis (ctx) { } } //获取元数据模型 -async function getMetadataModels (ctx) { +async function getMetadataModels(ctx) { try { const models = ctx.fs.dc.models; const { modelTypes } = ctx.query; @@ -281,7 +281,7 @@ async function getMetadataModels (ctx) { } //新建库表元数据 -async function postMetadataDatabases (ctx) { +async function postMetadataDatabases(ctx) { try { const { name, code, catalog, parent } = ctx.request.body; const models = ctx.fs.dc.models; @@ -318,7 +318,7 @@ async function postMetadataDatabases (ctx) { } //修改库表元数据 -async function putMetadataDatabases (ctx) { +async function putMetadataDatabases(ctx) { try { const { id } = ctx.params; const { catalog, name, code } = ctx.request.body; @@ -354,7 +354,7 @@ async function putMetadataDatabases (ctx) { } } //删除库表元数据 -async function delMetadataDatabases (ctx) { +async function delMetadataDatabases(ctx) { const transaction = await ctx.fs.dc.orm.transaction(); try { const models = ctx.fs.dc.models; @@ -409,7 +409,7 @@ async function delMetadataDatabases (ctx) { } } //获取库表元数据基本信息 -async function getMetadataDatabasesById (ctx) { +async function getMetadataDatabasesById(ctx) { try { const models = ctx.fs.dc.models; const { id } = ctx.params; @@ -440,7 +440,7 @@ async function getMetadataDatabasesById (ctx) { } //打标元数据 -async function postTagMetadata (ctx) { +async function postTagMetadata(ctx) { const transaction = await ctx.fs.dc.orm.transaction(); try { const { tags, database, file, restapi } = ctx.request.body; @@ -481,7 +481,7 @@ async function postTagMetadata (ctx) { } //获取元数据已打标数据 -async function getTagMetadata (ctx) { +async function getTagMetadata(ctx) { try { const models = ctx.fs.dc.models; const { id } = ctx.params; @@ -525,12 +525,28 @@ async function getTagMetadata (ctx) { } } //申请资源 -async function postMetadataResourceApplications (ctx) { +async function postMetadataResourceApplications(ctx) { try { - const { resourceName, applyBy, resourceType, resourceId, restServiceId } = ctx.request.body; + const { resourceName, applyBy, resourceType, resourceId, restServiceId, resourceCatalogId } = ctx.request.body; const models = ctx.fs.dc.models; if (restServiceId) { - await models.ResourceConsumption.create({ applyAt: moment(), approveState: '审批中', ...ctx.request.body }); + let resetapi = await models.RestfulApi.findOne({ + where: { id: restServiceId }, + include: [{ + model: models.ResourceCatalog, + attributes: ['id', 'name'], + include: [{ + model: models.Organization, + attributes: ['id', 'name'], + }] + }] + }) + + const dataToSave = { applyAt: moment(), approveState: '审批中', ...ctx.request.body } + if (resetapi && resetapi.resourceCatalog && resetapi.resourceCatalog.organization) { + dataToSave.orgId = resetapi.resourceCatalog.organization.id + } + await models.ResourceConsumption.create(dataToSave); ctx.body = { message: '申请资源成功' } ctx.status = 200; } else { @@ -538,7 +554,6 @@ async function postMetadataResourceApplications (ctx) { ctx.status = 400; ctx.body = { message: '参数不全,请重新申请资源' } } else { - const postOne = await models.ResourceConsumption.findOne({ where: { applyBy: applyBy, resourceName: resourceName, resourceId, resourceType, approve_remarks: null } }); @@ -546,7 +561,17 @@ async function postMetadataResourceApplications (ctx) { ctx.status = 400; ctx.body = { message: '该用户已申请过该元数据资源' } } else { - await models.ResourceConsumption.create({ applyAt: moment(), approveState: '审批中', ...ctx.request.body }); + let resourceCatalog = await models.ResourceCatalog.findOne({ + where: { id: resourceCatalogId }, + include: [ + { model: models.Organization } + ] + }) + const dataToSave = { applyAt: moment(), approveState: '审批中', ...ctx.request.body } + if (resourceCatalog && resourceCatalog.organization) { + dataToSave.orgId = resourceCatalog.organization.id + } + await models.ResourceConsumption.create(dataToSave); ctx.body = { message: '申请资源成功' } ctx.status = 200; } @@ -563,7 +588,7 @@ async function postMetadataResourceApplications (ctx) { } //获取元数据资源申请记录 -async function getMetadataResourceApplications (ctx) { +async function getMetadataResourceApplications(ctx) { try { const models = ctx.fs.dc.models; const { resourceNames, type } = ctx.query; @@ -585,7 +610,7 @@ async function getMetadataResourceApplications (ctx) { } //新建文件元数据 -async function postMetadataFiles (ctx) { +async function postMetadataFiles(ctx) { try { const { name, catalog, type, fileName } = ctx.request.body; const models = ctx.fs.dc.models; @@ -614,7 +639,7 @@ async function postMetadataFiles (ctx) { } } //修改文件元数据 -async function putMetadataFiles (ctx) { +async function putMetadataFiles(ctx) { try { const { id } = ctx.params; const { updateFileName } = ctx.query; @@ -654,7 +679,7 @@ async function putMetadataFiles (ctx) { } } //删除文件元数据 -async function delMetadataFiles (ctx) { +async function delMetadataFiles(ctx) { const transaction = await ctx.fs.dc.orm.transaction(); try { const models = ctx.fs.dc.models; @@ -702,7 +727,7 @@ async function delMetadataFiles (ctx) { } //新建接口元数据 -async function postMetadataRestapis (ctx) { +async function postMetadataRestapis(ctx) { try { const { name, catalog, method, url } = ctx.request.body; const models = ctx.fs.dc.models; @@ -732,7 +757,7 @@ async function postMetadataRestapis (ctx) { } //修改接口元数据 -async function putMetadataRestapis (ctx) { +async function putMetadataRestapis(ctx) { try { const { id } = ctx.params; const { catalog, name, method, url } = ctx.request.body; @@ -766,7 +791,7 @@ async function putMetadataRestapis (ctx) { } } //删除接口元数据 -async function delMetadataRestapis (ctx) { +async function delMetadataRestapis(ctx) { const transaction = await ctx.fs.dc.orm.transaction(); try { const models = ctx.fs.dc.models; @@ -814,7 +839,7 @@ async function delMetadataRestapis (ctx) { } //获取对表的库与字段信息 -async function listStructuredData (ctx) { +async function listStructuredData(ctx) { try { const models = ctx.fs.dc.models; const { id, parent } = ctx.query; diff --git a/api/app/lib/controllers/resourceConsumption/index.js b/api/app/lib/controllers/resourceConsumption/index.js index 302aeac..7f76a13 100644 --- a/api/app/lib/controllers/resourceConsumption/index.js +++ b/api/app/lib/controllers/resourceConsumption/index.js @@ -5,7 +5,7 @@ function getApproveList(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; - const { page, limit, applyAt, approveState, resourceName, applyBy, applyById, state, } = ctx.query; + const { page, limit, applyAt, approveState, resourceName, applyBy, applyById, state, orgId, approveId } = ctx.query; let errMsg = { message: '获取消费审批列表失败' } try { @@ -71,6 +71,16 @@ function getApproveList(opts) { option.where.approveState = approveState } + if (approveState == '已审批') { + if (approveId) { + option.include[1].where = { '$approveUser.id$': approveId } + } + } + + if (orgId) { + option.where.orgId = orgId + } + if (state == 1) { option.where.approveState = '已审批' option.where.token = { $ne: null } @@ -79,6 +89,8 @@ function getApproveList(opts) { option.where.approveState = '已审批' option.where.token = null option.where.approveRemarks = { $ne: null } + + } if (state == 3) { option.where.approveState = '审批中' diff --git a/api/app/lib/models/resource_consumption.js b/api/app/lib/models/resource_consumption.js index 084b3c1..e31aa8f 100644 --- a/api/app/lib/models/resource_consumption.js +++ b/api/app/lib/models/resource_consumption.js @@ -3,140 +3,149 @@ 'use strict'; module.exports = dc => { - const DataTypes = dc.ORM; - const sequelize = dc.orm; - const ResourceConsumption = sequelize.define("resourceConsumption", { - id: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: "ID唯一标识", - primaryKey: true, - field: "id", - autoIncrement: true, - unique: "t_resource_consumption_id_uindex" - }, - resourceId: { - type: DataTypes.INTEGER, - allowNull: true, - defaultValue: null, - comment: "资源id", - primaryKey: false, - field: "resource_id", - autoIncrement: false - }, - resourceName: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "资源名称", - primaryKey: false, - field: "resource_name", - autoIncrement: false - }, - resourceType: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "资源类型", - primaryKey: false, - field: "resource_type", - autoIncrement: false - }, - applyBy: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: "申请人", - primaryKey: false, - field: "apply_by", - autoIncrement: false, - references: { - key: "id", - model: "tUser" - } - }, - applyAt: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: null, - comment: "申请时间", - primaryKey: false, - field: "apply_at", - autoIncrement: false - }, - requirements: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "需求描述", - primaryKey: false, - field: "requirements", - autoIncrement: false - }, - approveState: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "审批状态", - primaryKey: false, - field: "approve_state", - autoIncrement: false - }, - approveBy: { - type: DataTypes.INTEGER, - allowNull: true, - defaultValue: null, - comment: "审批人", - primaryKey: false, - field: "approve_by", - autoIncrement: false, - references: { - key: "id", - model: "tUser" - } - }, - approveAt: { - type: DataTypes.DATE, - allowNull: true, - defaultValue: null, - comment: "审批时间", - primaryKey: false, - field: "approve_at", - autoIncrement: false - }, - approveRemarks: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "审批意见", - primaryKey: false, - field: "approve_remarks", - autoIncrement: false - }, - token: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "令牌", - primaryKey: false, - field: "token", - autoIncrement: false - }, - restServiceId: { - type: DataTypes.INTEGER, - allowNull: true, - defaultValue: null, - comment: "rest服务id", - primaryKey: false, - field: "rest_service_id", - autoIncrement: false - }, - }, { - tableName: "t_resource_consumption", - comment: "", - indexes: [] - }); - dc.models.ResourceConsumption = ResourceConsumption; - return ResourceConsumption; + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const ResourceConsumption = sequelize.define("resourceConsumption", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: "ID唯一标识", + primaryKey: true, + field: "id", + autoIncrement: true, + unique: "t_resource_consumption_id_uindex" + }, + resourceId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: "资源id", + primaryKey: false, + field: "resource_id", + autoIncrement: false + }, + resourceName: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "资源名称", + primaryKey: false, + field: "resource_name", + autoIncrement: false + }, + resourceType: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "资源类型", + primaryKey: false, + field: "resource_type", + autoIncrement: false + }, + applyBy: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: "申请人", + primaryKey: false, + field: "apply_by", + autoIncrement: false, + references: { + key: "id", + model: "tUser" + } + }, + applyAt: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: null, + comment: "申请时间", + primaryKey: false, + field: "apply_at", + autoIncrement: false + }, + requirements: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "需求描述", + primaryKey: false, + field: "requirements", + autoIncrement: false + }, + approveState: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "审批状态", + primaryKey: false, + field: "approve_state", + autoIncrement: false + }, + approveBy: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: "审批人", + primaryKey: false, + field: "approve_by", + autoIncrement: false, + references: { + key: "id", + model: "tUser" + } + }, + approveAt: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: "审批时间", + primaryKey: false, + field: "approve_at", + autoIncrement: false + }, + approveRemarks: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "审批意见", + primaryKey: false, + field: "approve_remarks", + autoIncrement: false + }, + token: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "令牌", + primaryKey: false, + field: "token", + autoIncrement: false + }, + restServiceId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: "rest服务id", + primaryKey: false, + field: "rest_service_id", + autoIncrement: false + }, + orgId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: "申请资源所属机构id", + primaryKey: false, + field: "orgId", + autoIncrement: false + } + }, { + tableName: "t_resource_consumption", + comment: "", + indexes: [] + }); + dc.models.ResourceConsumption = ResourceConsumption; + return ResourceConsumption; }; \ No newline at end of file diff --git a/scripts/0.0.14/03_alter_t_resource_consumption.sql b/scripts/0.0.14/03_alter_t_resource_consumption.sql new file mode 100644 index 0000000..a43f25f --- /dev/null +++ b/scripts/0.0.14/03_alter_t_resource_consumption.sql @@ -0,0 +1,4 @@ +alter table t_resource_consumption + add "orgId" int; + +comment on column t_resource_consumption."orgId" is '申请资源所属机构id'; \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/containers/databasesTable.js b/web/client/src/sections/metadataManagement/containers/databasesTable.js index 36b81a0..8f3b569 100644 --- a/web/client/src/sections/metadataManagement/containers/databasesTable.js +++ b/web/client/src/sections/metadataManagement/containers/databasesTable.js @@ -106,7 +106,7 @@ const DatabaseTable = (props) => { } const onConfirmResource = (values) => { - dispatch(metadataManagement.postMetadataResourceApplications(values)).then(res => { + dispatch(metadataManagement.postMetadataResourceApplications({ resourceCatalogId, ...values })).then(res => { if (res.success) { onSearch(); setResourceModalVisible(false); } @@ -361,7 +361,7 @@ const DatabaseTable = (props) => { } } -function mapStateToProps (state) { +function mapStateToProps(state) { const { global, auth, metadataDatabases, metadataModels, tagList, tagMetadata, metadataResourceApplications } = state; return { user: auth.user, diff --git a/web/client/src/sections/metadataManagement/containers/filesTable.js b/web/client/src/sections/metadataManagement/containers/filesTable.js index 1ab54f3..c1f26f9 100644 --- a/web/client/src/sections/metadataManagement/containers/filesTable.js +++ b/web/client/src/sections/metadataManagement/containers/filesTable.js @@ -107,7 +107,7 @@ const FilesTable = (props) => { } const onConfirmResource = (values) => { - dispatch(metadataManagement.postMetadataResourceApplications(values)).then(res => { + dispatch(metadataManagement.postMetadataResourceApplications({ resourceCatalogId, ...values })).then(res => { if (res.success) { onSearch(); setResourceModalVisible(false); } diff --git a/web/client/src/sections/metadataManagement/containers/restapisTable.js b/web/client/src/sections/metadataManagement/containers/restapisTable.js index 5ebefc1..7824a79 100644 --- a/web/client/src/sections/metadataManagement/containers/restapisTable.js +++ b/web/client/src/sections/metadataManagement/containers/restapisTable.js @@ -84,7 +84,7 @@ const RestapisTable = (props) => { } const onConfirmResource = (values) => { - dispatch(metadataManagement.postMetadataResourceApplications(values)).then(res => { + dispatch(metadataManagement.postMetadataResourceApplications({ resourceCatalogId, ...values })).then(res => { if (res.success) { onSearch(); setResourceModalVisible(false); } diff --git a/web/client/src/sections/resourceConsumption/containers/approve.js b/web/client/src/sections/resourceConsumption/containers/approve.js index 956ac1e..f3d5c11 100644 --- a/web/client/src/sections/resourceConsumption/containers/approve.js +++ b/web/client/src/sections/resourceConsumption/containers/approve.js @@ -6,7 +6,7 @@ import { Tabs, Form, Input, DatePicker, Button, Table } from 'antd'; import { Func } from '$utils' -function Approve({ loading, clientHeight, actions, dispatch, }) { +function Approve({ loading, clientHeight, actions, dispatch, user }) { const { resourceConsumption } = actions const [tabsKey, setTabsKey] = useState("stay") @@ -24,7 +24,11 @@ function Approve({ loading, clientHeight, actions, dispatch, }) { let resourceData = (params) => { let data = params || query - dispatch(resourceConsumption.getApproveList({ approveState: tabsKey == 'stay' ? "审批中" : '已审批', ...formData, ...data, })).then(res => { + dispatch(resourceConsumption.getApproveList({ + approveState: tabsKey == 'stay' ? "审批中" : '已审批', ...formData, ...data, + orgId: user?.orgId, + approveId: (params?.approveState == '已审批' && user?.username != 'SuperAdmin') ? user?.id : null + })).then(res => { if (res.success) { setProTableList(res.payload.data) } @@ -86,7 +90,7 @@ function Approve({ loading, clientHeight, actions, dispatch, }) { dataIndex: 'handle', // ellipsis: true, render: (text, record) => { - let enable = Func?.isOrgOrSuperAdmin(record?.applyUser?.organization?.id) + let enable = Func?.isOrgOrSuperAdmin(record?.orgId) return enable ?