Browse Source

增加巡检次数统计功能

master
liujiangyong 2 years ago
parent
commit
a1420a50af
  1. 19
      api/app/lib/controllers/patrolManage/patrolRecord.js

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

@ -1,6 +1,6 @@
'use strict';
async function findPatrolRecord (ctx, next) {
async function findPatrolRecord(ctx, next) {
let rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' };
try {
@ -125,8 +125,9 @@ async function findPatrolRecord (ctx, next) {
}
}
async function addPatrolRecord (ctx, next) {
async function addPatrolRecord(ctx, next) {
let error = { name: 'addError', message: '新增巡检记录失败' };
const transaction = await ctx.fs.dc.orm.transaction();
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
@ -139,11 +140,23 @@ async function addPatrolRecord (ctx, next) {
const lastInspectionTime = pointRecord.length ? pointRecord[0].dataValues.inspectionTime : null;
let record = { patrolPlanId, lastInspectionTime, inspectionTime, points, alarm, pointId }
await models.PatrolRecord.create(record);
await models.PatrolRecord.create(record, transaction);
// 更新巡检次数统计
const curPlanRecord = await models.PatrolRecord.findAndCountAll({
where: { patrolPlanId }
});
const patrolCount = curPlanRecord.count;
await models.PatrolPlan.update({ patrolCount }, {
where: { id: patrolPlanId },
transaction
})
await transaction.commit();
ctx.status = 204;
error = null
} catch (error) {
await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {

Loading…
Cancel
Save