@@ -9,8 +9,7 @@ function operatorItem() {
99 version : "1.0.0" ,
1010 inputs : Mock . Random . integer ( 1 , 5 ) ,
1111 outputs : Mock . Random . integer ( 1 , 5 ) ,
12- runtime : Mock . Random . pick ( [ "Python" , "Java" , "Scala" ] ) ,
13- settings : {
12+ settings : JSON . stringify ( {
1413 host : { type : "input" , label : "主机地址" , value : "localhost" } ,
1514 port : { type : "input" , label : "端口" , value : "3306" } ,
1615 database : { type : "input" , label : "数据库名" , value : "" } ,
@@ -36,14 +35,15 @@ function operatorItem() {
3635 value : [ ] ,
3736 options : [ "feature1" , "feature2" , "feature3" ] ,
3837 } ,
39- } ,
38+ } ) ,
39+ categories : [ Mock . Random . pick ( [ 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) ] ,
4040 isStar : Mock . Random . boolean ( ) ,
4141 createdAt : Mock . Random . datetime ( "yyyy-MM-dd HH:mm:ss" ) ,
4242 updatedAt : Mock . Random . datetime ( "yyyy-MM-dd HH:mm:ss" ) ,
4343 } ;
4444}
4545
46- const operatorList = new Array ( 10 ) . fill ( null ) . map ( operatorItem ) ;
46+ const operatorList = new Array ( 50 ) . fill ( null ) . map ( operatorItem ) ;
4747
4848// 清洗任务数据
4949function cleaningTaskItem ( ) {
@@ -73,7 +73,10 @@ function cleaningTemplateItem() {
7373 id : Mock . Random . guid ( ) . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, "" ) ,
7474 name : Mock . Random . ctitle ( 5 , 15 ) ,
7575 description : Mock . Random . csentence ( 5 , 25 ) ,
76- instance : operatorList ,
76+ instance : operatorList . slice (
77+ Mock . Random . integer ( 0 , 5 ) ,
78+ Mock . Random . integer ( 6 , 50 )
79+ ) ,
7780 category : Mock . Random . ctitle ( 3 , 8 ) ,
7881 createdAt : Mock . Random . datetime ( "yyyy-MM-dd HH:mm:ss" ) ,
7982 updatedAt : Mock . Random . datetime ( "yyyy-MM-dd HH:mm:ss" ) ,
@@ -82,12 +85,41 @@ function cleaningTemplateItem() {
8285
8386const cleaningTemplateList = new Array ( 15 ) . fill ( null ) . map ( cleaningTemplateItem ) ;
8487
88+ const categoryTree = [
89+ {
90+ id : 1 ,
91+ name : "modal" ,
92+ count : 7 ,
93+ categories : [
94+ { id : 3 , name : "text" , count : 3 , type : null , parentId : null } ,
95+ { id : 4 , name : "image" , count : 0 , type : null , parentId : null } ,
96+ { id : 5 , name : "audio" , count : 0 , type : null , parentId : null } ,
97+ { id : 6 , name : "video" , count : 0 , type : null , parentId : null } ,
98+ {
99+ id : 7 ,
100+ name : "multimodal" ,
101+ count : 0 ,
102+ type : null ,
103+ parentId : null ,
104+ } ,
105+ ] ,
106+ } ,
107+ {
108+ id : 2 ,
109+ name : "language" ,
110+ count : 3 ,
111+ categories : [
112+ { id : 8 , name : "python" , count : 2 , type : null , parentId : null } ,
113+ { id : 9 , name : "java" , count : 1 , type : null , parentId : null } ,
114+ ] ,
115+ } ,
116+ ] ;
117+
85118module . exports = function ( router ) {
86119 // 获取清洗任务列表
87120 router . get ( API . queryCleaningTasksUsingGet , ( req , res ) => {
88121 const { page = 0 , size = 10 , status } = req . query ;
89122 let filteredTasks = cleaningTaskList ;
90- console . log ( req . query ) ;
91123
92124 if ( status ) {
93125 filteredTasks = cleaningTaskList . filter ( ( task ) => task . status === status ) ;
@@ -289,4 +321,181 @@ module.exports = function (router) {
289321 } ) ;
290322 }
291323 } ) ;
324+
325+ // 获取算子列表
326+ router . post ( API . queryOperatorsUsingPost , ( req , res ) => {
327+ const {
328+ page = 0 ,
329+ size = 20 ,
330+ categories = [ ] ,
331+ operatorName = "" ,
332+ labelName = "" ,
333+ isStar,
334+ } = req . body ;
335+
336+ let filteredOperators = operatorList ;
337+
338+ // 按分类筛选
339+ if ( categories && categories . length > 0 ) {
340+ filteredOperators = filteredOperators . filter ( ( op ) =>
341+ categories . includes ( op . category . id )
342+ ) ;
343+ }
344+
345+ // 按名称搜索
346+ if ( operatorName ) {
347+ filteredOperators = filteredOperators . filter ( ( op ) =>
348+ op . name . toLowerCase ( ) . includes ( operatorName . toLowerCase ( ) )
349+ ) ;
350+ }
351+
352+ // 按标签筛选
353+ if ( labelName ) {
354+ filteredOperators = filteredOperators . filter ( ( op ) =>
355+ op . labels . some ( ( label ) => label . name . includes ( labelName ) )
356+ ) ;
357+ }
358+
359+ // 按收藏状态筛选
360+ if ( typeof isStar === "boolean" ) {
361+ filteredOperators = filteredOperators . filter (
362+ ( op ) => op . isStar === isStar
363+ ) ;
364+ }
365+
366+ const startIndex = page * size ;
367+ const endIndex = startIndex + parseInt ( size ) ;
368+ const pageData = filteredOperators . slice ( startIndex , endIndex ) ;
369+
370+ res . send ( {
371+ code : "0" ,
372+ msg : "Success" ,
373+ data : {
374+ content : pageData ,
375+ totalElements : filteredOperators . length ,
376+ totalPages : Math . ceil ( filteredOperators . length / size ) ,
377+ size : parseInt ( size ) ,
378+ number : parseInt ( page ) ,
379+ first : page === 0 ,
380+ last : page >= Math . ceil ( filteredOperators . length / size ) - 1 ,
381+ } ,
382+ } ) ;
383+ } ) ;
384+
385+ // 获取算子详情
386+ router . get ( API . queryOperatorByIdUsingGet , ( req , res ) => {
387+ const { id } = req . params ;
388+ const operator = operatorList . find ( ( op ) => op . id === id ) ;
389+
390+ if ( operator ) {
391+ // 增加浏览次数模拟
392+ operator . viewCount = ( operator . viewCount || 0 ) + 1 ;
393+
394+ res . send ( {
395+ code : "0" ,
396+ msg : "Success" ,
397+ data : operator ,
398+ } ) ;
399+ } else {
400+ res . status ( 404 ) . send ( {
401+ error : "OPERATOR_NOT_FOUND" ,
402+ message : "算子不存在" ,
403+ timestamp : new Date ( ) . toISOString ( ) ,
404+ } ) ;
405+ }
406+ } ) ;
407+
408+ // 更新算子信息
409+ router . put ( API . updateOperatorByIdUsingPut , ( req , res ) => {
410+ const { id } = req . params ;
411+ const index = operatorList . findIndex ( ( op ) => op . id === id ) ;
412+
413+ if ( index !== - 1 ) {
414+ operatorList [ index ] = {
415+ ...operatorList [ index ] ,
416+ ...req . body ,
417+ updatedAt : new Date ( ) . toISOString ( ) ,
418+ } ;
419+
420+ res . send ( {
421+ code : "0" ,
422+ msg : "Operator updated successfully" ,
423+ data : operatorList [ index ] ,
424+ } ) ;
425+ } else {
426+ res . status ( 404 ) . send ( {
427+ error : "OPERATOR_NOT_FOUND" ,
428+ message : "算子不存在" ,
429+ timestamp : new Date ( ) . toISOString ( ) ,
430+ } ) ;
431+ }
432+ } ) ;
433+
434+ // 创建算子
435+ router . post ( API . createOperatorUsingPost , ( req , res ) => {
436+ const { name, description, version, category, documentation } = req . body ;
437+
438+ const newOperator = {
439+ ...operatorItem ( ) ,
440+ ...req . body ,
441+ id : Mock . Random . guid ( ) . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, "" ) ,
442+ name,
443+ description,
444+ version,
445+ category :
446+ typeof category === "string"
447+ ? { id : category , name : category }
448+ : category ,
449+ documentation,
450+ status : "REVIEWING" ,
451+ downloadCount : 0 ,
452+ rating : 0 ,
453+ ratingCount : 0 ,
454+ isStar : false ,
455+ createdAt : new Date ( ) . toISOString ( ) ,
456+ updatedAt : new Date ( ) . toISOString ( ) ,
457+ } ;
458+
459+ operatorList . push ( newOperator ) ;
460+
461+ res . status ( 201 ) . send ( {
462+ code : "0" ,
463+ msg : "Operator created successfully" ,
464+ data : newOperator ,
465+ } ) ;
466+ } ) ;
467+
468+ // 上传算子
469+ router . post ( API . uploadOperatorUsingPost , ( req , res ) => {
470+ const { description } = req . body ;
471+
472+ const newOperator = {
473+ ...operatorItem ( ) ,
474+ description : description || "通过文件上传创建的算子" ,
475+ status : "REVIEWING" ,
476+ downloadCount : 0 ,
477+ rating : 0 ,
478+ ratingCount : 0 ,
479+ isStar : false ,
480+ createdAt : new Date ( ) . toISOString ( ) ,
481+ updatedAt : new Date ( ) . toISOString ( ) ,
482+ } ;
483+
484+ operatorList . push ( newOperator ) ;
485+
486+ res . status ( 201 ) . send ( {
487+ code : "0" ,
488+ msg : "Operator uploaded successfully" ,
489+ data : newOperator ,
490+ } ) ;
491+ } ) ;
492+
493+ // 获取算子分类树
494+ router . get ( API . queryCategoryTreeUsingGet , ( req , res ) => {
495+ res . send ( {
496+ code : "0" ,
497+ msg : "Success" ,
498+ data : categoryTree ,
499+ } ) ;
500+ } ) ;
292501} ;
0 commit comments