@ -1,15 +1,15 @@
'use strict' ;
const { QueryTypes } = require ( 'sequelize' ) ;
async function reportList ( ctx ) {
async function reportList ( ctx ) {
try {
const models = ctx . fs . dc . models ;
const { limit , page , startTime , endTime , keyword , userId , reportType } = ctx . query
const { limit , page , startTime , endTime , keyword , userId , reportType , isTop } = ctx . query
let findOption = {
where : {
} ,
attributes : [ 'id' , 'road' , 'time' , 'projectType' , 'roadSectionStart' , 'roadSectionEnd' , 'reportType' , 'content' , 'longitude' , 'latitude' ] ,
attributes : [ 'id' , 'road' , 'time' , 'projectType' , 'roadSectionStart' , 'roadSectionEnd' , 'reportType' , 'content' , 'longitude' , 'latitude' ] ,
include : [ {
model : models . User ,
attributes : [ 'name' ]
@ -39,7 +39,15 @@ async function reportList (ctx) {
if ( reportType ) {
findOption . where . reportType = reportType
}
const reportRes = await models . Report . findAll ( findOption )
let reportRes = null ;
if ( isTop ) {
const sqlStr = 'select * from (SELECT R.*, "row_number"() OVER(PARTITION BY R.user_id ORDER BY R."time" DESC) AS NEWINDEX FROM report AS R ) AS NR WHERE NEWINDEX = 1'
const sequelize = ctx . fs . dc . ORM ;
reportRes = sequelize . query ( sqlStr , { type : QueryTypes . SELECT } ) ;
} else {
reportRes = await models . Report . findAll ( findOption )
}
ctx . status = 200 ;
ctx . body = reportRes
@ -52,7 +60,7 @@ async function reportList (ctx) {
}
}
async function reportPosition ( ctx ) {
async function reportPosition ( ctx ) {
try {
const models = ctx . fs . dc . models ;
const { startTime , endTime , userId , reportType } = ctx . query
@ -102,7 +110,7 @@ async function reportPosition (ctx) {
}
}
async function reportDetail ( ctx ) {
async function reportDetail ( ctx ) {
try {
const models = ctx . fs . dc . models ;
const { reportId } = ctx . params
@ -124,7 +132,7 @@ async function reportDetail (ctx) {
}
}
async function createReport ( ctx ) {
async function createReport ( ctx ) {
try {
const { userId } = ctx . fs . api
const models = ctx . fs . dc . models ;
@ -146,7 +154,7 @@ async function createReport (ctx) {
}
}
async function deleteReport ( ctx ) {
async function deleteReport ( ctx ) {
try {
const models = ctx . fs . dc . models ;
const { reportId } = ctx . params ;