6 changed files with 320 additions and 2 deletions
@ -0,0 +1,117 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
async function reportList (ctx) { |
||||
|
try { |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const { limit, page, startTime, endTime, keyword } = ctx.query |
||||
|
let findOption = { |
||||
|
where: { |
||||
|
|
||||
|
}, |
||||
|
attributes: ['id', 'road', 'time'], |
||||
|
include: [{ |
||||
|
model: models.User, |
||||
|
attributes: ['name'] |
||||
|
}], |
||||
|
} |
||||
|
if (limit) { |
||||
|
findOption.limit = limit |
||||
|
} |
||||
|
if (page && limit) { |
||||
|
findOption.offset = page * limit |
||||
|
} |
||||
|
if (startTime && endTime) { |
||||
|
findOption.where = { |
||||
|
time: { |
||||
|
'$between': [startTime, endTime] |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if (keyword) { |
||||
|
findOption.where.road = { |
||||
|
'$like': `%${keyword}%` |
||||
|
} |
||||
|
} |
||||
|
const reportRes = await models.Report.findAll(findOption) |
||||
|
|
||||
|
ctx.status = 200; |
||||
|
ctx.body = reportRes |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: typeof error == 'string' ? error : undefined |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function reportDetail (ctx) { |
||||
|
try { |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const { reportId } = ctx.params |
||||
|
|
||||
|
const reportRes = await models.Report.findOne({ |
||||
|
where: { |
||||
|
id: reportId |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
ctx.status = 200; |
||||
|
ctx.body = reportRes |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: typeof error == 'string' ? error : undefined |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function createReport (ctx) { |
||||
|
try { |
||||
|
const { userId } = ctx.fs.api |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const data = ctx.request.body; |
||||
|
|
||||
|
await models.Report.create({ |
||||
|
...data, |
||||
|
userId, |
||||
|
time: new Date(), |
||||
|
}) |
||||
|
|
||||
|
ctx.status = 204 |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: typeof error == 'string' ? error : undefined |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function deleteReport (ctx) { |
||||
|
try { |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const { reportId } = ctx.params; |
||||
|
|
||||
|
await models.Report.destroy({ |
||||
|
where: { |
||||
|
id: reportId |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
ctx.status = 204 |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: typeof error == 'string' ? error : undefined |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// TODO 小程序填写道路名称的时候的道路筛选 是一起都返回 还是不断传关键字搜索返回
|
||||
|
|
||||
|
module.exports = { |
||||
|
reportList, reportDetail, createReport, deleteReport, |
||||
|
}; |
@ -0,0 +1,160 @@ |
|||||
|
/* eslint-disable*/ |
||||
|
'use strict'; |
||||
|
|
||||
|
module.exports = dc => { |
||||
|
const DataTypes = dc.ORM; |
||||
|
const sequelize = dc.orm; |
||||
|
const Report = sequelize.define("report", { |
||||
|
id: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: true, |
||||
|
field: "id", |
||||
|
autoIncrement: true, |
||||
|
unique: "report_id_uindex" |
||||
|
}, |
||||
|
reportType: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: "上报类型 巡查:patrol / 养护:conserve", |
||||
|
primaryKey: false, |
||||
|
field: "report_type", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
projectType: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: "工程类型 道路:road / 桥梁:birdge / 涵洞:culvert", |
||||
|
primaryKey: false, |
||||
|
field: "project_type", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
road: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "road", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
roadSectionStart: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "road_section_start", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
roadSectionEnd: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "road_section_end", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
longitude: { |
||||
|
type: DataTypes.DOUBLE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "longitude", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
latitude: { |
||||
|
type: DataTypes.DOUBLE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "latitude", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
content: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "content", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
scenePic: { |
||||
|
type: DataTypes.ARRAY(DataTypes.STRING), |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "scene_pic", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
conserveBeforePic: { |
||||
|
type: DataTypes.ARRAY(DataTypes.STRING), |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "conserve_before_pic", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
conserveUnderwayPic: { |
||||
|
type: DataTypes.ARRAY(DataTypes.STRING), |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "conserve_underway_pic", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
conserveAfterPic: { |
||||
|
type: DataTypes.ARRAY(DataTypes.STRING), |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "conserve_after_pic", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
userId: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "user_id", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
time: { |
||||
|
type: DataTypes.DATE, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "time", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
address: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "address", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
}, { |
||||
|
tableName: "report", |
||||
|
comment: "", |
||||
|
indexes: [] |
||||
|
}); |
||||
|
dc.models.Report = Report; |
||||
|
return Report; |
||||
|
}; |
@ -0,0 +1,17 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const report = require('../../controllers/report'); |
||||
|
|
||||
|
module.exports = function (app, router, opts) { |
||||
|
app.fs.api.logAttr['GET/report/list'] = { content: '获取上报列表', visible: false }; |
||||
|
router.get('/report/list', report.reportList); |
||||
|
|
||||
|
app.fs.api.logAttr['GET/report/:reportId/detail'] = { content: '获取上报详情', visible: false }; |
||||
|
router.get('/report/:reportId//detail', report.reportDetail); |
||||
|
|
||||
|
app.fs.api.logAttr['POST/report'] = { content: '创建上报', visible: false }; |
||||
|
router.post('/report', report.createReport); |
||||
|
|
||||
|
app.fs.api.logAttr['DEL/report/:reportId'] = { content: '删除上报', visible: false }; |
||||
|
router.del('/report/:reportId', report.deleteReport); |
||||
|
} |
Loading…
Reference in new issue