'use strict' //查询路政 const moment = require('moment'); async function getRoadadministration(ctx, next) { try { const { limit = 10, page,keyword,startTime,endTime} = ctx.query; // const distinct = 'false' == includeCount ? false : true//gis大屏需要总设备,后台管理不需要include的统计 const models = ctx.fs.dc.models; let where = {}; if(startTime && endTime){ where.enforcementdate = { $between: [moment(startTime).format('YYYY-MM-DD'), moment(endTime).format('YYYY-MM-DD')] } } let findObj = { order: [["id", "desc"]], where: where, }; if (page && limit) { findObj.limit = Number(limit) findObj.offset = Number(page - 1) * Number(limit) } let rslt = await models.Roadadministration.findAndCountAll(findObj); ctx.body = rslt; ctx.status = 200; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { "message": "获取路政数据失败" } } } // 新增路政 function addRoadadministration(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; try { let rslt = ctx.request.body; await models.Roadadministration.create(rslt) ctx.status = 204; ctx.body = { message: '添加路政数据成功' } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: '添加路政失败' } } } } // 删除路政 function delRoadadministration(opts) { return async function (ctx, next) { try { const models = ctx.fs.dc.models; const { id } = ctx.params; await models.Roadadministration.destroy({ where: { id: id } }) ctx.status = 204; ctx.body = { message: '删除路政信息' } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: '删除健康体检' } } } } // 修改路政 function editRoadadministration(opts) { return async function (ctx, next) { try { const models = ctx.fs.dc.models; const { id } = ctx.params; const body = ctx.request.body; await models.Roadadministration.update( body, { where: { id: id, } } ) ctx.status = 204; ctx.body = { message: '修改健康体检数据成功' } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: '修改健康体检数据失败' } } } } module.exports = { getRoadadministration, addRoadadministration, delRoadadministration, editRoadadministration }