政务数据资源中心(Government data Resource center) 03专项3期主要建设内容
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.5 KiB

2 years ago
'use strict';
const moment = require('moment')
function getApproveList (opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
2 years ago
const { page, limit, applyAt, approveState, resourceName, applyBy, applyById, state } = ctx.query;
2 years ago
let errMsg = { message: '获取消费审批列表失败' }
try {
let option = {
where: {},
order: [["id", "desc"]],
distinct: true,
include: [{
model: models.User,
2 years ago
as: 'applyUser',
2 years ago
attributes: ['id', 'name']
2 years ago
}, {
2 years ago
model: models.User,
2 years ago
as: 'approveUser',
2 years ago
attributes: ['id', 'name']
},]
}
if (resourceName) {
option.where.resourceName = { $iLike: `%${resourceName}%` }
}
if (applyBy) {
2 years ago
option.include[0].where = { '$applyUser.name$': { $iLike: `%${applyBy}%` } }
2 years ago
}
if (applyById) {
option.where.applyBy = applyById
}
if (limit) {
option.limit = Number(limit)
}
if (page && limit) {
option.offset = Number(page) * Number(limit)
}
if (approveState) {
option.where.approveState = approveState
}
2 years ago
if (state == 1) {
option.where.approveState = '已审批'
option.where.token = { $ne: null }
}
if (state == 2) {
option.where.approveState = '已审批'
option.where.token = null
option.where.approveRemarks = { $ne: null }
}
if (state == 3) {
option.where.approveState = '审批中'
}
2 years ago
if (applyAt) {
option.where.applyAt = {
$between: [
moment(applyAt).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
moment(applyAt).endOf('day').format('YYYY-MM-DD HH:mm:ss')
]
}
}
const res = await models.ResourceConsumption.findAndCount(option);
ctx.status = 200;
ctx.body = res;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = errMsg
}
}
}
// 新增模型
function addModelManagement (opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
try {
const { attributeName, attributeCode, modelType } = ctx.request.body
const checkName = await models.MetaModel.findOne({ where: { attributeName, modelType } });
const checkCode = await models.MetaModel.findOne({ where: { attributeCode, modelType } });
if (checkName || checkCode) {
ctx.status = 400;
ctx.body = { message: checkName ? '该属性名称已存在' : "该属性代码已存在" }
} else {
let rslt = ctx.request.body;
await models.MetaModel.create(Object.assign({}, rslt))
ctx.status = 204;
ctx.body = { message: '新建模型成功' }
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '新建模型失败' }
}
}
}
// 修改模型
function postApprove (opts) {
return async function (ctx, next) {
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
const { id } = data
await models.ResourceConsumption.update(
data,
{ where: { id: id, } }
)
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '消费审批失败' }
}
}
}
// 删除模型
function deleteModelManagement (opts) {
return async function (ctx, next) {
try {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
await models.MetaModel.destroy({
where: {
id: id
}
})
ctx.status = 204;
ctx.body = { message: '删除模型成功' }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '删除模型失败' }
}
}
}
module.exports = {
// getModelManagementList,
// addModelManagement,
// editModelManagement,
// deleteModelManagement,
getApproveList,
postApprove,
}