'use strict'; function getAcquisitionLog(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; const { page, limit, taskName, logState, startTime, endTime } = ctx.query; let errMsg = { message: '获取采集任务失败' } const Op = ctx.fs.dc.ORM.Op; try { let searchWhere = {} let option = { where: searchWhere, order: [["id", "desc"]], include: [{ model: models.AcquisitionTask, as: 'acquisitionTask', include: [{ model: models.DataSource, }] }] } if (taskName) { searchWhere.$or = [ { '$acquisitionTask.task_name$': { $iLike: `%${taskName}%` } }, { '$acquisitionTask.dataSource.name$': { $iLike: `%${taskName}%` } }, ] } if (logState && logState != '全部') { searchWhere.success = logState == 'true' ? true : false } if (startTime && endTime) { searchWhere.startTime = { [Op.between]: [startTime, endTime] } } option.where = searchWhere let limit_ = limit || 10; let page_ = page || 1; let offset = (page_ - 1) * limit_; if (limit && page) { option.limit = limit_ option.offset = offset } const res = await models.AcquisitionLog.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 } } } module.exports = { getAcquisitionLog, }