Browse Source

巡检记录详情重置

master
巴林闲侠 2 years ago
parent
commit
43bbfa5aa2
  1. 59
      api/app/lib/controllers/patrolManage/patrolRecord.js
  2. 6
      api/app/lib/index.js
  3. 73
      web/client/src/sections/patrolManage/containers/patrolRecord.js

59
api/app/lib/controllers/patrolManage/patrolRecord.js

@ -1,33 +1,52 @@
'use strict';
async function findPatrolRecord(ctx, next) {
async function findPatrolRecord (ctx, next) {
let rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' };
try {
const models = ctx.fs.dc.models;
const { startTime, endTime, alarm, patrolPlanId, pointId } = ctx.params;
// patrolPlanId传all查所有
let generalInclude = [{
model: models.PatrolPlan,
attributes: ['name']
}]
if (patrolPlanId == 'all') {
/* 如果有startTime && endTime,查询所有符合条件的数据 */
if (startTime !== 'null' && endTime !== 'null') {
if (pointId !== 'null') {
if (alarm == 'null') {
rslt = await models.PatrolRecord.findAll({
where: { inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } },
where: {
inspectionTime: { $between: [startTime, endTime] },
pointId: { $in: pointId.split(',') }
},
include: generalInclude
});
} else {
rslt = await models.PatrolRecord.findAll({
where: { alarm, inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } },
where: {
alarm,
inspectionTime: { $between: [startTime, endTime] },
pointId: { $in: pointId.split(',') }
},
include: generalInclude
});
}
} else {
if (alarm == 'null') {
rslt = await models.PatrolRecord.findAll({
where: { inspectionTime: { $between: [startTime, endTime] } },
where: {
inspectionTime: { $between: [startTime, endTime] }
},
include: generalInclude
});
} else {
rslt = await models.PatrolRecord.findAll({
where: { alarm, inspectionTime: { $between: [startTime, endTime] } },
where: {
alarm, inspectionTime: { $between: [startTime, endTime] }
},
include: generalInclude
});
}
}
@ -37,7 +56,9 @@ async function findPatrolRecord(ctx, next) {
if (pointId !== 'null') {
a = await models.PatrolRecord.findAll({
where: { pointId: { $in: pointId.split(',') } },
include: generalInclude
});
}
rslt = pointId.split(',').map(i => {
return a.filter(t => t.pointId == i).sort((a, b) => b.id - a.id)[0] || null
@ -47,11 +68,22 @@ async function findPatrolRecord(ctx, next) {
if (startTime !== 'null' && endTime !== 'null') {
if (pointId !== 'null') {
rslt = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } },
where: {
patrolPlanId: { $in: patrolPlanId.split(',') },
alarm,
inspectionTime: { $between: [startTime, endTime] },
pointId: { $in: pointId.split(',') }
},
include: generalInclude
});
} else {
rslt = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, inspectionTime: { $between: [startTime, endTime] } },
where: {
patrolPlanId: { $in: patrolPlanId.split(',') },
alarm,
inspectionTime: { $between: [startTime, endTime] }
},
include: generalInclude
});
}
@ -60,11 +92,18 @@ async function findPatrolRecord(ctx, next) {
/* 如果没有startTime && endTime,查询每个点位最新一条符合条件的数据 */
if (pointId !== 'null') {
a = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, pointId: { $in: pointId.split(',') } },
where: {
patrolPlanId: { $in: patrolPlanId.split(',') },
pointId: { $in: pointId.split(',') }
},
include: generalInclude
});
} else {
a = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') } },
where: {
patrolPlanId: { $in: patrolPlanId.split(',') }
},
include: generalInclude
});
}
@ -86,7 +125,7 @@ async function findPatrolRecord(ctx, next) {
}
}
async function addPatrolRecord(ctx, next) {
async function addPatrolRecord (ctx, next) {
let error = { name: 'addError', message: '新增巡检记录失败' };
try {
const models = ctx.fs.dc.models;

6
api/app/lib/index.js

@ -53,11 +53,15 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
require(`./models/${filename}`)(dc)
});
const { Department, User, UserResource, Resource, Project, Point, PatrolPlan,
const { Department, User, UserResource, Resource, Project, Point,
PatrolPlan, PatrolRecord,
CheckItems, CheckItemsGroup,
PatrolTemplate, PatrolTemplateCheckItems
} = dc.models;
PatrolRecord.belongsTo(PatrolPlan, { foreignKey: 'patrolPlanId', targetKey: 'id' });
PatrolPlan.hasMany(PatrolRecord, { foreignKey: 'patrolPlanId', sourceKey: 'id' });
UserResource.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' });
User.hasMany(UserResource, { foreignKey: 'userId', sourceKey: 'id' });

73
web/client/src/sections/patrolManage/containers/patrolRecord.js

@ -36,46 +36,67 @@ const PatrolRecord = (props) => {
title: '结构物名称',
dataIndex: 'name',
key: 'name',
width: '10%',
showInDetail: true,
render: (text, record, index) => {
return !record.points?.project ? '' : <div style={{ width: 100 }}>{record.points.project.name}</div>
return !record.points?.project ? '' : <div>{record.points.project.name}</div>
}
}, {
title: '巡检人',
title: '巡检计划',
dataIndex: 'name',
key: 'name',
width: '10%',
showInDetail: true,
render: (text, record, index) => {
return !record.patrolPlan ? '' : <div>{record.patrolPlan.name}</div>
}
}, {
title: '巡检点位',
dataIndex: 'type',
key: 'type',
showInDetail: true,
width: '10%',
render: (text, record, index) => {
return !record.points?.user ? '' : <div style={{ width: 100 }}>{record.points.user.name}</div>
return !record.points?.user ? '' : <div>{record.points.itemData.name}</div>
}
}, {
title: '巡检点位',
title: '巡检',
dataIndex: 'type',
key: 'type',
showInDetail: true,
width: '10%',
render: (text, record, index) => {
return !record.points?.user ? '' : <div style={{ width: 100 }}>{record.points.itemData.name}</div>
return !record.points?.user ? '' : <div>{record.points.user.name}</div>
}
}, {
title: '巡检单位',
dataIndex: 'type',
showInDetail: true,
key: 'type',
width: '10%',
render: (text, record, index) => {
return !record.points?.user ? '' : <div style={{ width: 100 }}>{record.points.user.department.name}</div>
return !record.points?.user ? '' : <div>{record.points.user.department.name}</div>
}
}, {
title: '巡检频次',
dataIndex: 'describe',
key: 'describe',
showInDetail: true,
width: '10%',
render: (text, record, index) => {
return !record.points ? '' : <div style={{ width: 100 }}>{record.points.frequency}</div>
return !record.points ? '' : <div>{record.points.frequency}</div>
}
}, {
title: '上次巡检日期',
dataIndex: 'describe',
showInDetail: true,
key: 'describe',
render: (text, record, index) => moment(record.lastInspectionTime).format('YYYY-MM-DD HH:mm:ss') || '--'
}, {
title: '本次巡检日期',
dataIndex: 'describe',
key: 'describe',
showInDetail: true,
render: (text, record, index) => moment(record.inspectionTime).format('YYYY-MM-DD HH:mm:ss') || '--'
}, {
title: '巡检结果',
@ -168,32 +189,50 @@ const PatrolRecord = (props) => {
onCancel={() => setShowDetail(false)}
footer={[<Button onClick={() => setShowDetail(false)}>关闭</Button>]}
>
<Row align='middle' justify='center' style={{ marginBottom: 10 }}>
{(() => {
let dataArr = []
columns.forEach(c => {
if (c.showInDetail) {
dataArr.push(
<>
<Row>
<Col span={6} style={{
// textAlign: 'justify', textAlignLast: 'justify'
}}>{c.title} </Col>
<Col span={18}>{c.render('', modelData)}</Col>
</Row>
</>
)
}
})
return dataArr
})()}
{/* <Row align='middle' justify='center' style={{ marginBottom: 10 }}>
当前点位{modelData?.points?.itemData?.name}
</Row>
<Row align='middle' justify='center' style={{ marginBottom: 10 }}>
当前位置{modelData?.points?.address}
</Row>
<Row align='middle' justify='center' style={{ marginBottom: 10 }}>
巡检结果{modelData.alarm? '异常':'正常'}
巡检结果{modelData.alarm ? '异常' : '正常'}
</Row>
{ !modelData.alarm? '':
{!modelData.alarm ? '' :
<Row align='middle' justify='center' style={{ marginBottom: 10 }}>
巡检详情{modelData?.points?.msgInp}
</Row> }
{ !modelData.alarm? '':
</Row>}
{!modelData.alarm ? '' :
<Row align='middle' justify='center' style={{ marginBottom: 10 }}>
异常等级{modelData?.points?.changeThree}
</Row> }
{ !modelData.alarm? '':<Row align='middle' justify='center' style={{ marginBottom: 10 }}>
{ modelData?.points?.imgs?.map(rs => <img key={rs} src={`/_file-server/${rs}`} style={{ display: 'inline-block', width: 260, marginBottom: 10 }} />)}
</Row> }
</Row>}
{!modelData.alarm ? '' : <Row align='middle' justify='center' style={{ marginBottom: 10 }}>
{modelData?.points?.imgs?.map(rs => <img key={rs} src={`/_file-server/${rs}`} style={{ display: 'inline-block', width: 260, marginBottom: 10 }} />)}
</Row>} */}
</Modal>
</>
)
}
function mapStateToProps(state) {
function mapStateToProps (state) {
const { auth, global } = state;
return {
user: auth.user,

Loading…
Cancel
Save