diff --git a/api/app/lib/controllers/patrolManage/patrolReport.js b/api/app/lib/controllers/patrolManage/patrolReport.js new file mode 100644 index 0000000..9ff6c05 --- /dev/null +++ b/api/app/lib/controllers/patrolManage/patrolReport.js @@ -0,0 +1,36 @@ +'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: {} + }; + 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, +} \ No newline at end of file diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 6f6cb92..492d7ef 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -54,7 +54,7 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq }); const { Department, User, UserResource, Resource, Project, Point, - PatrolPlan, PatrolRecord, + PatrolPlan, PatrolRecord, ReportInfo, CheckItems, CheckItemsGroup, PatrolTemplate, PatrolTemplateCheckItems, PatrolRecordIssueHandle } = dc.models; @@ -93,6 +93,9 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq PatrolPlan.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' }); User.hasMany(PatrolPlan, { foreignKey: 'userId', sourceKey: 'id' }); + ReportInfo.belongsTo(Project, { foreignKey: 'projectId', targetKey: 'id' }); + Project.hasMany(ReportInfo, { foreignKey: 'projectId', sourceKey: 'id' }); + CheckItems.belongsTo(CheckItemsGroup, { foreignKey: 'groupId', targetKey: 'id' }); CheckItemsGroup.hasMany(CheckItems, { foreignKey: 'groupId', sourceKey: 'id' }); }; diff --git a/api/app/lib/models/report_info.js b/api/app/lib/models/report_info.js new file mode 100644 index 0000000..d4ffbe8 --- /dev/null +++ b/api/app/lib/models/report_info.js @@ -0,0 +1,60 @@ +/* eslint-disable*/ +'use strict'; + +module.exports = dc => { + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const ReportInfo = sequelize.define("reportInfo", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true, + }, + projectId: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: false, + field: "project_id", + autoIncrement: false + }, + excelPath: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: false, + field: "excel_path", + autoIncrement: false + }, + inspectTm: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: false, + field: "inspect_tm", + autoIncrement: false + }, + reportTm: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: false, + field: "report_tm", + autoIncrement: false + } + }, { + tableName: "report_info", + comment: "", + indexes: [] + }); + dc.models.ReportInfo = ReportInfo; + return ReportInfo; +}; \ No newline at end of file diff --git a/api/app/lib/routes/patrolManage/patrolReport.js b/api/app/lib/routes/patrolManage/patrolReport.js new file mode 100644 index 0000000..2732214 --- /dev/null +++ b/api/app/lib/routes/patrolManage/patrolReport.js @@ -0,0 +1,8 @@ +'use strict'; + +const patrolReport = require('../../controllers/patrolManage/patrolReport'); + +module.exports = function (app, router, opts) { + app.fs.api.logAttr['GET/patrolReport'] = { content: '获取巡检报告', visible: false }; + router.get('/patrolReport', patrolReport.getPatrolReport); +}; \ No newline at end of file diff --git a/weapp/package/inspectionReport/inspectionReport.js b/weapp/package/inspectionReport/inspectionReport.js index 9d4afcc..15ada30 100644 --- a/weapp/package/inspectionReport/inspectionReport.js +++ b/weapp/package/inspectionReport/inspectionReport.js @@ -18,7 +18,7 @@ Page({ endTime: new Date().getTime(), formatStartTime: moment(new Date().getTime()).format('YYYY-MM-DD'), formatEndTime: moment(new Date().getTime()).format('YYYY-MM-DD'), - report: [1, 2], // 巡检报告 + report: [], // 巡检报告 }, showPopup(e) { @@ -29,18 +29,13 @@ Page({ onClose(e) { const { item } = e.currentTarget.dataset; this.setData({ [`${item}Visible`]: false }); - console.log('请求报告') // 获取报告 - // const body = {} - // Request.get(getPatrolReport(body)).then(res => { - // console.log(res) - // }) + this.getPatrolReport(); }, onStruChange(e) { if (e.detail) { - const { value, index } = e.detail; - console.log(`当前值:${value}, 当前索引:${index}`); + const { index } = e.detail; this.setData({ curStru: index }) @@ -60,16 +55,18 @@ Page({ }); }, - download() { + download(e) { + const { url } = e.currentTarget.dataset; wx.showLoading({ title: '下载中...' }); wx.downloadFile({ - url: 'http://10.8.16.102:5900/_file-server/project/d178aef7-4a88-41c4-aa82-4254fbcf884e/16518450744352.jpg', // 仅为示例,并非真实的资源 + url: getApp().globalData.imgUrl + url, success(downloadRes) { wx.hideLoading(); if (downloadRes.statusCode === 200) { const filePath = downloadRes.tempFilePath; wx.openDocument({ filePath: filePath, + showMenu: true, success: function (res) { console.log('打开文档成功'); } @@ -79,13 +76,35 @@ Page({ }) }, + getPatrolReport() { + const { structures, curStru, formatStartTime, formatEndTime } = this.data; + const params = { + projectId: structures[curStru].id, + startTime: formatStartTime + ' 00:00:00', + endTime: formatEndTime + ' 23:59:59', + } + wx.showLoading({ title: '查询中...' }); + Request.get(getPatrolReport(params)).then(res => { + wx.hideLoading(); + this.setData({ + report: res.rows.map(r => { + const fileName = r.excelPath.substring(r.excelPath.lastIndexOf('/') + 1); + return { ...r, fileName } + }) + }) + }) + }, + getStructuresList() { this.setData({ struLoading: true }); Request.get(getStructuresList()).then(res => { this.setData({ struLoading: false, - structures: ['全部', ...res.rows.map(s => s.name)] - }) + structures: [ + { name: '全部', id: '' }, + ...res.rows.map(s => ({ name: s.name, id: s.id })) + ] + }, () => { this.getPatrolReport(); }) }) }, diff --git a/weapp/package/inspectionReport/inspectionReport.wxml b/weapp/package/inspectionReport/inspectionReport.wxml index e29cddb..ae63a38 100644 --- a/weapp/package/inspectionReport/inspectionReport.wxml +++ b/weapp/package/inspectionReport/inspectionReport.wxml @@ -1,9 +1,9 @@ - + - + @@ -18,9 +18,9 @@ - 2143654.docx + {{item.fileName}} - 下载 + 打开 diff --git a/weapp/utils/getApiUrl.js b/weapp/utils/getApiUrl.js index 747be14..cf8313e 100644 --- a/weapp/utils/getApiUrl.js +++ b/weapp/utils/getApiUrl.js @@ -55,6 +55,7 @@ exports.getStructuresList = () => { } // 获取巡检报告 -exports.getPatrolReport = () => { - return `/getPatrolReport` +exports.getPatrolReport = (query) => { + const { projectId, startTime, endTime } = query; + return `/patrolReport?projectId=${projectId}&startTime=${startTime}&endTime=${endTime}` } \ No newline at end of file