You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

113 lines
3.0 KiB

'use strict';
async function getPatrolPlan(ctx, next) {
try {
const models = ctx.fs.dc.models;
const { limit, page } = ctx.query;
let options = {
include: [{
required: true,
model: models.User,
attributes: ['id', 'name'],
include: [{
required: true,
model: models.Department,
attributes: ['id', 'name'],
}]
}, {
required: true,
model: models.Project,
attributes: ['id', 'name'],
}]
};
if (limit) {
options.limit = Number(limit);
}
if (page && limit) {
options.offset = Number(page) * Number(limit);
}
let res = await models.PatrolPlan.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": "获取巡检计划失败"
}
}
}
async function createPatrolPlan(ctx, next) {
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
const { name, way, structureId, startTime, endTime, frequency, points, userId } = data;
let plan = { name, way, structureId, startTime, endTime, frequency, points, userId };
await models.PatrolPlan.create(plan);
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
"message": '新增巡检计划失败'
}
}
}
async function updatePatrolPlan(ctx, next) {
try {
let errMsg = '修改巡检计划失败';
const models = ctx.fs.dc.models;
const data = ctx.request.body;
const { name, way, structureId, startTime, endTime, frequency, points, userId } = data;
let plan = { name, way, structureId, startTime, endTime, frequency, points, userId };
if (data && data.id) {
await models.PatrolPlan.update(plan, {
where: { id: data.id }
})
} else {
errMsg = '请传入巡检计划id';
throw errMsg;
}
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
"message": errMsg
}
}
}
async function delPatrolPlan(ctx, next) {
try {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
await models.PatrolPlan.destroy({
where: { id }
})
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
"message": '删除巡检计划失败'
}
}
}
module.exports = {
getPatrolPlan,
createPatrolPlan,
updatePatrolPlan,
delPatrolPlan,
}