@@ -77,7 +77,7 @@ export class ResourcesService {
7777 pageNumber = PageEnum . PAGE_NUMBER ,
7878 pageSize = PageEnum . PAGE_SIZE ,
7979 title,
80- type ,
80+ resourcesType ,
8181 parentId,
8282 status,
8383 } = queryResourcesDto ;
@@ -88,12 +88,14 @@ export class ResourcesService {
8888 if ( [ ( StatusEnum . NORMAL , StatusEnum . FORBIDDEN ) ] . includes ( status ) ) {
8989 queryMap . set ( 'status' , Equal ( status + '' ) ) ;
9090 }
91- if ( [ 0 , 1 , 2 ] . includes ( type ) ) {
92- queryMap . set ( 'type ' , Equal ( type + '' ) ) ;
91+ if ( [ 0 , 1 , 2 ] . includes ( resourcesType ) ) {
92+ queryMap . set ( 'resourcesType ' , Equal ( resourcesType + '' ) ) ;
9393 }
9494
9595 if ( parentId ) {
9696 queryMap . set ( 'parentId' , Equal ( parentId + '' ) ) ;
97+ } else {
98+ queryMap . set ( 'parentId' , Equal ( '-1' ) ) ;
9799 }
98100 const [ data , total ] = await this . resourcesRepository
99101 . createQueryBuilder ( )
@@ -103,8 +105,27 @@ export class ResourcesService {
103105 . printSql ( )
104106 . where ( mapToObj ( queryMap ) )
105107 . getManyAndCount ( ) ;
108+ // 抽取全部的id
109+ const resourcesIdList = data . map ( ( item ) => item . id ) ;
110+ const resourcesEntityList : Pick < ResourcesEntity , 'parentId' > [ ] =
111+ await this . resourcesRepository . find ( {
112+ where : { parentId : In ( resourcesIdList ) } ,
113+ select : [ 'parentId' ] ,
114+ } ) ;
115+ // 组成map[parentId] = true
116+ const resourcesMap = new Map < number , boolean > ( ) ;
117+ for ( const item of resourcesEntityList ) {
118+ resourcesMap . set ( item . parentId , true ) ;
119+ }
120+ const result : ResourcesVo [ ] = [ ] ;
121+ for ( const item of data ) {
122+ result . push ( {
123+ ...item ,
124+ hasChildren : resourcesMap . get ( item . id ) ,
125+ } ) ;
126+ }
106127 return {
107- data,
128+ data : result ,
108129 total,
109130 pageNumber : + pageNumber ,
110131 pageSize : + pageSize ,
@@ -115,7 +136,7 @@ export class ResourcesService {
115136 * @Author : 水痕
116137 * @Date : 2023-10-08 08:07:30
117138 * @LastEditors : 水痕
118- * @Description : 根据资源目录
139+ * @Description : 根据资源模块
119140 * @return {* }
120141 */
121142 async getResourceCatalogApi ( ) : Promise < SimplenessResourceVo [ ] > {
0 commit comments