From 2fab3b1c0ab8a12749d4c85e09b4935e29189068 Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Thu, 2 Nov 2023 11:02:03 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E7=94=A8=E6=88=B7=20=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=85=B3=E8=81=94=E6=9C=BA=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/auth/index.js | 7 +- api/app/lib/controllers/organization/index.js | 14 +- api/app/lib/index.js | 6 +- api/app/lib/models/resource_catalog.js | 121 ++++++++------- api/app/lib/models/user.js | 139 ++++++++++-------- .../components/memberModal.js | 11 +- .../memberManagement/containers/member.js | 14 +- .../components/resourceCatalogModal.js | 18 ++- .../containers/latestMetadata.js | 12 +- 9 files changed, 197 insertions(+), 145 deletions(-) diff --git a/api/app/lib/controllers/auth/index.js b/api/app/lib/controllers/auth/index.js index 03d418c..ac242fd 100644 --- a/api/app/lib/controllers/auth/index.js +++ b/api/app/lib/controllers/auth/index.js @@ -6,7 +6,7 @@ const CryptoJS = require('crypto-js'); const moment = require('moment'); const uuid = require('uuid'); -async function login (ctx, next) { +async function login(ctx, next) { // const transaction = await ctx.fs.dc.orm.transaction(); try { const models = ctx.fs.dc.models; @@ -23,6 +23,9 @@ async function login (ctx, next) { username: params.username, password: password, }, + include: [{ + model: models.Organization + }] }); } if (userRes) { @@ -60,7 +63,7 @@ async function login (ctx, next) { } } -async function logout (ctx) { +async function logout(ctx) { try { const models = ctx.fs.dc.models; const params = ctx.request.body; diff --git a/api/app/lib/controllers/organization/index.js b/api/app/lib/controllers/organization/index.js index 26c40c4..fceb9d7 100644 --- a/api/app/lib/controllers/organization/index.js +++ b/api/app/lib/controllers/organization/index.js @@ -51,10 +51,11 @@ function addOrganization(opts) { const models = ctx.fs.dc.models; try { const { name, code } = ctx.request.body - const checkName = await models.Organization.findOne({ where: { name, code } }); - if (checkName) { + const checkName = await models.Organization.findOne({ where: { name } }); + const checkCode = await models.Organization.findOne({ where: { code } }); + if (checkName || checkCode) { ctx.status = 400; - ctx.body = { message: "该机构名称&代码组合已存在" } + ctx.body = { message: "机构名称或代码不能重复" } } else { let rslt = ctx.request.body; await models.Organization.create(Object.assign({}, rslt)) @@ -79,10 +80,11 @@ function editOrganization(opts) { const { id } = ctx.params; const body = ctx.request.body; const { name, code } = ctx.request.body - const checkName = await models.Organization.findOne({ where: { id: { $not: id }, name, code } }); - if (checkName) { + const checkName = await models.Organization.findOne({ where: { id: { $not: id }, name } }); + const checkCode = await models.Organization.findOne({ where: { id: { $not: id }, code } }); + if (checkName || checkCode) { ctx.status = 400; - ctx.body = { message: '该机构名称&代码组合已存在' } + ctx.body = { message: '机构名称或代码不能重复' } } else { await models.Organization.update( body, diff --git a/api/app/lib/index.js b/api/app/lib/index.js index d66abed..aabd9b3 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -57,7 +57,7 @@ module.exports.models = function (dc) { const { DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi, AcquisitionLog, ResourceCatalog, BusinessMetadataDatabase, BusinessMetadataFile, BusinessMetadataRestapi, ResourceConsumption, BusinessRule, StandardDoc, DbStatistics - , RestfulApi, RestfulApiRecord + , RestfulApi, RestfulApiRecord, Organization } = dc.models; AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' }); @@ -91,7 +91,7 @@ module.exports.models = function (dc) { ResourceConsumption.belongsTo(User, { foreignKey: 'applyBy', targetKey: 'id', as: "applyUser" }); - RestfulApi.hasMany(ResourceConsumption, { foreignKey: 'restServiceId', targetKey: 'id',}); + RestfulApi.hasMany(ResourceConsumption, { foreignKey: 'restServiceId', targetKey: 'id', }); ResourceConsumption.belongsTo(User, { foreignKey: 'approveBy', targetKey: 'id', as: 'approveUser' }); @@ -102,4 +102,6 @@ module.exports.models = function (dc) { DataSource.hasMany(DbStatistics, { foreignKey: 'sourceId', sourceKey: 'id' }) RestfulApiRecord.belongsTo(RestfulApi, { foreignKey: 'restServiceId', targetKey: 'id' }); + + User.belongsTo(Organization, { foreignKey: 'orgId', targetKey: 'id' }); }; diff --git a/api/app/lib/models/resource_catalog.js b/api/app/lib/models/resource_catalog.js index 6f24402..8e6febf 100644 --- a/api/app/lib/models/resource_catalog.js +++ b/api/app/lib/models/resource_catalog.js @@ -3,60 +3,69 @@ 'use strict'; module.exports = dc => { - const DataTypes = dc.ORM; - const sequelize = dc.orm; - const ResourceCatalog = sequelize.define("resourceCatalog", { - id: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: "唯一标识", - primaryKey: true, - field: "id", - autoIncrement: true, - unique: "t_resource_catalog_id_uindex" - }, - name: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "名称", - primaryKey: false, - field: "name", - autoIncrement: false - }, - code: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "代码", - primaryKey: false, - field: "code", - autoIncrement: false - }, - description: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "描述", - primaryKey: false, - field: "description", - autoIncrement: false - }, - parent: { - type: DataTypes.INTEGER, - allowNull: true, - defaultValue: null, - comment: "父级目录", - primaryKey: false, - field: "parent", - autoIncrement: false - } - }, { - tableName: "t_resource_catalog", - comment: "", - indexes: [] - }); - dc.models.ResourceCatalog = ResourceCatalog; - return ResourceCatalog; + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const ResourceCatalog = sequelize.define("resourceCatalog", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: "唯一标识", + primaryKey: true, + field: "id", + autoIncrement: true, + unique: "t_resource_catalog_id_uindex" + }, + name: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "名称", + primaryKey: false, + field: "name", + autoIncrement: false + }, + code: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "代码", + primaryKey: false, + field: "code", + autoIncrement: false + }, + description: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "描述", + primaryKey: false, + field: "description", + autoIncrement: false + }, + parent: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: "父级目录", + primaryKey: false, + field: "parent", + autoIncrement: false + }, + orgId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "orgId", + autoIncrement: false + } + }, { + tableName: "t_resource_catalog", + comment: "", + indexes: [] + }); + dc.models.ResourceCatalog = ResourceCatalog; + return ResourceCatalog; }; \ No newline at end of file diff --git a/api/app/lib/models/user.js b/api/app/lib/models/user.js index cf38fb6..e75f978 100644 --- a/api/app/lib/models/user.js +++ b/api/app/lib/models/user.js @@ -3,70 +3,79 @@ 'use strict'; module.exports = dc => { - const DataTypes = dc.ORM; - const sequelize = dc.orm; - const User = sequelize.define("user", { - id: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: "唯一标识", - primaryKey: true, - field: "id", - autoIncrement: true, - unique: "t_user_id_uindex" - }, - name: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "姓名", - primaryKey: false, - field: "name", - autoIncrement: false - }, - username: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "用户名", - primaryKey: false, - field: "username", - autoIncrement: false - }, - password: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "密码", - primaryKey: false, - field: "password", - autoIncrement: false - }, - role: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "角色", - primaryKey: false, - field: "role", - autoIncrement: false - }, - enabled: { - type: DataTypes.BOOLEAN, - allowNull: true, - defaultValue: true, - comment: "是否启用", - primaryKey: false, - field: "enabled", - autoIncrement: false - } + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const User = sequelize.define("user", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: "唯一标识", + primaryKey: true, + field: "id", + autoIncrement: true, + unique: "t_user_id_uindex" + }, + name: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "姓名", + primaryKey: false, + field: "name", + autoIncrement: false + }, + username: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "用户名", + primaryKey: false, + field: "username", + autoIncrement: false + }, + password: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "密码", + primaryKey: false, + field: "password", + autoIncrement: false + }, + role: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "角色", + primaryKey: false, + field: "role", + autoIncrement: false + }, + enabled: { + type: DataTypes.BOOLEAN, + allowNull: true, + defaultValue: true, + comment: "是否启用", + primaryKey: false, + field: "enabled", + autoIncrement: false + }, + orgId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "orgId", + autoIncrement: false + } - }, { - tableName: "t_user", - comment: "", - indexes: [] - }); - dc.models.User = User; - return User; + }, { + tableName: "t_user", + comment: "", + indexes: [] + }); + dc.models.User = User; + return User; }; \ No newline at end of file diff --git a/web/client/src/sections/memberManagement/components/memberModal.js b/web/client/src/sections/memberManagement/components/memberModal.js index e2e7a26..b535342 100644 --- a/web/client/src/sections/memberManagement/components/memberModal.js +++ b/web/client/src/sections/memberManagement/components/memberModal.js @@ -11,7 +11,7 @@ import { } from '@ant-design/pro-form'; export default (props) => { - const { title, triggerRender, editData = null, onFinish, paramsName } = props; + const { title, triggerRender, editData = null, onFinish, paramsName, organization } = props; const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 16 } }; const initialValues = editData ? { ...editData, @@ -68,6 +68,15 @@ export default (props) => { label="角色" /> + ({ label: s.name, value: s.id }))} + name="orgId" + label="机构" + /> + + { queryData(); + dispatch(actions.organization.getOrganizationList()); }, [pageSize, currentPage]); const columns = [ @@ -73,6 +70,7 @@ function Member(props) { title="编辑用户" onFinish={onFinish} key="editUser" + organization={organization} />) options.push( @@ -213,14 +212,15 @@ function Member(props) { function mapStateToProps(state) { const { - auth, global, datasources, member + auth, global, datasources, member, organization } = state; return { loading: datasources.isRequesting, clientHeight: global.clientHeight, actions: global.actions, member: member?.data || {}, - user: auth.user + user: auth.user, + organization: organization?.data?.rows || [], }; } diff --git a/web/client/src/sections/metadataManagement/components/resourceCatalogModal.js b/web/client/src/sections/metadataManagement/components/resourceCatalogModal.js index 279fc0a..c486c60 100644 --- a/web/client/src/sections/metadataManagement/components/resourceCatalogModal.js +++ b/web/client/src/sections/metadataManagement/components/resourceCatalogModal.js @@ -1,8 +1,8 @@ import React, { useEffect, useState } from 'react'; -import { Modal, Input, Form, message } from 'antd'; +import { Modal, Input, Form, message, Select } from 'antd'; const { TextArea } = Input; const ResourceCatalogModal = (props) => { - const { resourceCatalog, onConfirm, onCancel, editData } = props; + const { resourceCatalog, onConfirm, onCancel, editData, organization } = props; const [form] = Form.useForm(); useEffect(() => { }, []); @@ -73,6 +73,20 @@ const ResourceCatalogModal = (props) => { })]}> + + + + + { - const { user, dispatch, actions, history, clientHeight, resourceCatalog, isRequesting, location, match } = props; + const { user, dispatch, actions, history, clientHeight, resourceCatalog, isRequesting, location, match, organization } = props; const { metadataManagement } = actions; const [resourceCatalogData, setResourceCatalogData] = useState([]); const [selectedKeys, setSelectedKeys] = useState([]); @@ -30,6 +30,7 @@ const LatestMetadata = (props) => { useEffect(() => { const jumpSelectedKey = sessionStorage.getItem('jumpSelectedKey') || null; initData(true, jumpSelectedKey); + dispatch(actions.organization.getOrganizationList()); }, []) const initData = (configRefresh, jumpSelectedKey) => { dispatch(metadataManagement.getResourceCatalog()).then(res => { @@ -241,18 +242,21 @@ const LatestMetadata = (props) => { resourceCatalog={resourceCatalog} editData={editData} onCancel={() => setModalVisible(false)} - onConfirm={onConfirm} /> : '' + onConfirm={onConfirm} + organization={organization} + /> : '' } } function mapStateToProps(state) { - const { global, auth, resourceCatalog } = state; + const { global, auth, resourceCatalog, organization } = state; return { user: auth.user, actions: global.actions, clientHeight: global.clientHeight, resourceCatalog: resourceCatalog?.data || [], - isRequesting: resourceCatalog.isRequesting + isRequesting: resourceCatalog.isRequesting, + organization: organization?.data?.rows || [], }; } export default connect(mapStateToProps)(LatestMetadata)