Browse Source

巡检报告接口+小程序接入

master
liujiangyong 2 years ago
parent
commit
3ab3e9c0ec
  1. 36
      api/app/lib/controllers/patrolManage/patrolReport.js
  2. 5
      api/app/lib/index.js
  3. 60
      api/app/lib/models/report_info.js
  4. 8
      api/app/lib/routes/patrolManage/patrolReport.js
  5. 43
      weapp/package/inspectionReport/inspectionReport.js
  6. 8
      weapp/package/inspectionReport/inspectionReport.wxml
  7. 5
      weapp/utils/getApiUrl.js

36
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,
}

5
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' });
};

60
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;
};

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

43
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(); })
})
},

8
weapp/package/inspectionReport/inspectionReport.wxml

@ -1,9 +1,9 @@
<!-- package/inspectionReport/inspectionReport.wxml -->
<view>
<van-cell-group>
<van-cell title="结构物" value="{{structures[curStru]}}" is-link arrow-direction="down" data-item="stru" bind:click="showPopup" />
<van-cell title="结构物" value="{{structures[curStru].name}}" is-link arrow-direction="down" data-item="stru" bind:click="showPopup" />
<van-popup show="{{ struVisible }}" data-item="stru" bind:close="onClose" round position="bottom" custom-style="height: 40%">
<van-picker columns="{{ structures }}" bind:change="onStruChange" default-index="{{ curStru }}" loading="{{struLoading}}" />
<van-picker columns="{{ structures }}" value-key="name" bind:change="onStruChange" default-index="{{ curStru }}" loading="{{struLoading}}" />
</van-popup>
<van-cell title="时间" title-width="80rpx" value="{{formatStartTime + ' - ' + formatEndTime}}" is-link arrow-direction="down" data-item="date" bind:click="showPopup" />
<van-popup show="{{ dateVisible }}" data-item="date" bind:close="onClose" round position="bottom" custom-style="height: 40%">
@ -18,9 +18,9 @@
<view class="file-box" wx:for="{{report}}">
<view class="file">
<image class="logo" src="/images/word.svg"></image>
<view>2143654.docx</view>
<view>{{item.fileName}}</view>
</view>
<van-button type="primary" size="small" color="#169bd5" bind:click="download">下载</van-button>
<van-button type="primary" size="small" color="#169bd5" data-url="{{item.excelPath}}" bind:click="download">打开</van-button>
</view>
</view>
<view wx:else>

5
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}`
}
Loading…
Cancel
Save