Browse Source

(*)资源审批增加机构id字段

master
peng.peng 1 year ago
parent
commit
3dc5e2995c
  1. 33
      api/app/lib/controllers/latestMetadata/index.js
  2. 14
      api/app/lib/controllers/resourceConsumption/index.js
  3. 9
      api/app/lib/models/resource_consumption.js
  4. 4
      scripts/0.0.14/03_alter_t_resource_consumption.sql
  5. 2
      web/client/src/sections/metadataManagement/containers/databasesTable.js
  6. 2
      web/client/src/sections/metadataManagement/containers/filesTable.js
  7. 2
      web/client/src/sections/metadataManagement/containers/restapisTable.js
  8. 10
      web/client/src/sections/resourceConsumption/containers/approve.js

33
api/app/lib/controllers/latestMetadata/index.js

@ -527,10 +527,26 @@ async function getTagMetadata (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;
}

14
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 = '审批中'

9
api/app/lib/models/resource_consumption.js

@ -132,6 +132,15 @@ module.exports = dc => {
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: "",

4
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';

2
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);
}

2
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);
}

2
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);
}

10
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 ? <Button type="link" onClick={() => {
setEditData(record)
setApproveModal(true);

Loading…
Cancel
Save