'use strict';

async function getPatrolReport(ctx, next) {
    try {
        const models = ctx.fs.dc.models;
        const { limit, page, projectId, startTime, endTime } = ctx.query;
        let options = {
            where: {},
            include: [{
                model: models.Project
            }]
        };
        if (limit) {
            options.limit = Number(limit);
        }
        if (page && limit) {
            options.offset = Number(page) * Number(limit);
        }
        if (projectId) {
            options.where.projectId = projectId;
        }
        if (startTime && endTime) {
            options.where.inspectTm = { $between: [startTime, endTime] };
        }
        const res = await models.ReportInfo.findAndCountAll(options);
        ctx.status = 200;
        ctx.body = res;
    } catch (error) {
        ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
        ctx.status = 400;
        ctx.body = {
            "message": "获取巡检报告失败"
        }
    }
}

module.exports = {
    getPatrolReport,
}