@ -30,6 +30,73 @@ async function inspection (ctx) {
}
}
}
}
async function inspectionList ( ctx ) {
try {
const models = ctx . fs . dc . models ;
const { clickHouse } = ctx . app . fs
const { timeStart , timeEnd , projectId , appId , noted } = ctx . query
let findOption = {
where : {
} ,
order : [ [ 'id' , 'DESC' ] ] ,
include : [ {
model : models . ProjectApp ,
required : Boolean ( appId || projectId ) ,
where : appId ? {
id : appId
} : undefined ,
include : {
model : models . ProjectCorrelation ,
required : Boolean ( projectId ) ,
where : projectId ? {
id : projectId
} : undefined ,
attributes : {
exclude : [ 'anxinProjectId' , 'createTime' , 'createUser' ]
}
}
} ]
}
if ( timeStart && timeEnd ) {
findOption . where . createTime = { $between : [ moment ( timeStart ) . format ( ) , moment ( timeEnd ) . format ( ) ] }
}
if ( noted ) {
if ( noted == 'noted' ) {
findOption . where . notedTime = { $ne : null }
} else if ( noted == 'unnote' ) {
findOption . where . notedTime = null
}
}
const inspectionRes = await models . AppInspection . findAll ( findOption )
let notedUserIds = new Set ( )
for ( let ins of inspectionRes ) {
if ( ins . notedPepUserId ) {
notedUserIds . add ( ins . notedPepUserId )
}
}
let userPepRes = notedUserIds . size ?
await clickHouse . pepEmis . query ( ` SELECT DISTINCT user.id AS id, "user"."name" AS name FROM user WHERE user.id IN ( ${ [ ... notedUserIds ] . join ( ',' ) } ) ` ) . toPromise ( ) :
[ ]
for ( let ins of inspectionRes ) {
if ( ins . notedPepUserId ) {
const corUser = userPepRes . find ( up => up . id == ins . notedPepUserId )
ins . dataValues . notedPepUser = corUser ? corUser . name : ''
}
}
ctx . status = 200 ;
ctx . body = inspectionRes
} catch ( error ) {
ctx . fs . logger . error ( ` path: ${ ctx . path } , error: error ` ) ;
ctx . status = 400 ;
ctx . body = {
message : typeof error == 'string' ? error : undefined
}
}
}
async function notedInspection ( ctx ) {
async function notedInspection ( ctx ) {
try {
try {
const models = ctx . fs . dc . models ;
const models = ctx . fs . dc . models ;
@ -100,6 +167,23 @@ async function apiError (ctx) {
}
}
}
}
async function apiErrorList ( ctx ) {
try {
const models = ctx . fs . dc . models ;
const { clickHouse } = ctx . app . fs
const { } = ctx . query
ctx . status = 200 ;
ctx . body = [ ]
} catch ( error ) {
ctx . fs . logger . error ( ` path: ${ ctx . path } , error: error ` ) ;
ctx . status = 400 ;
ctx . body = {
message : typeof error == 'string' ? error : undefined
}
}
}
async function confirmApiError ( ctx ) {
async function confirmApiError ( ctx ) {
try {
try {
const models = ctx . fs . dc . models ;
const models = ctx . fs . dc . models ;
@ -125,7 +209,9 @@ async function confirmApiError (ctx) {
module . exports = {
module . exports = {
inspection ,
inspection ,
inspectionList ,
notedInspection ,
notedInspection ,
apiError ,
apiError ,
apiErrorList ,
confirmApiError ,
confirmApiError ,
} ;
} ;