@@ -73,6 +73,7 @@ func regApiDev(api fiber.Router) {
7373 api .Get ("/download" , handleDownload )
7474 api .Get ("/compare_assets" , getCompareAssets )
7575 api .Post ("/update_note" , handleUpdateNote )
76+ api .Post ("/del_bt_reports" , delBacktestReports )
7677}
7778
7879func onWsDev (c * websocket.Conn ) {
@@ -523,20 +524,25 @@ func getBtOptions(c *fiber.Ctx) error {
523524 }
524525
525526 // 处理策略列表
526- stratMap := make (map [string ]bool )
527+ stratMap := make (map [string ]int )
527528 for _ , o := range options {
528529 strats := strings .Split (o .Strats , "," )
529530 for _ , s := range strats {
530531 if s = strings .TrimSpace (s ); s != "" {
531- stratMap [s ] = true
532+ oldNum , _ := stratMap [s ]
533+ stratMap [s ] = oldNum + 1
532534 }
533535 }
534536 }
535- strats := make ([]string , 0 , len (stratMap ))
536- for s := range stratMap {
537- strats = append (strats , s )
537+ strats := make ([]core.StrVal [int ], 0 , len (stratMap ))
538+ for s , v := range stratMap {
539+ strats = append (strats , core.StrVal [int ]{
540+ Str : s , Val : v ,
541+ })
538542 }
539- sort .Strings (strats )
543+ sort .Slice (strats , func (i , j int ) bool {
544+ return strats [i ].Val > strats [j ].Val
545+ })
540546
541547 // 处理周期列表
542548 periodMap := make (map [string ]int )
@@ -1464,6 +1470,75 @@ func getCompareAssets(c *fiber.Ctx) error {
14641470 return c .Send (content )
14651471}
14661472
1473+ func delBacktestReports (c * fiber.Ctx ) error {
1474+ type DelArgs struct {
1475+ IDs []int64 `json:"ids"`
1476+ Hashes []string `json:"hashes"`
1477+ }
1478+ var args = new (DelArgs )
1479+ if err := base .VerifyArg (c , args , base .ArgBody ); err != nil {
1480+ return err
1481+ }
1482+
1483+ qu , conn , err2 := ormu .Conn ()
1484+ if err2 != nil {
1485+ return err2
1486+ }
1487+ defer conn .Close ()
1488+
1489+ // 构建files参数
1490+ files := make (map [string ]bool )
1491+ tasks := make ([]int64 , 0 , len (args .IDs ))
1492+ failNum := 0
1493+ for _ , id := range args .IDs {
1494+ task , err := qu .GetTask (context .Background (), id )
1495+ if err != nil {
1496+ failNum += 1
1497+ log .Error ("query task fail" , zap .Int64 ("id" , id ), zap .Error (err ))
1498+ continue
1499+ }
1500+ tasks = append (tasks , id )
1501+ if task .Path != "" {
1502+ path := filepath .Join (config .GetDataDir (), "backtest" , task .Path )
1503+ files [path ] = utils .Exists (path )
1504+ }
1505+ }
1506+ for _ , hash := range args .Hashes {
1507+ path := filepath .Join (config .GetDataDir (), "backtest" , hash )
1508+ files [path ] = utils .Exists (path )
1509+ rows , err := qu .FindTasks (context .Background (), ormu.FindTasksParams {
1510+ Path : hash ,
1511+ })
1512+ if err != nil {
1513+ log .Error ("FindTasks by hash fail" , zap .String ("hash" , hash ), zap .Error (err ))
1514+ continue
1515+ }
1516+ for _ , r := range rows {
1517+ tasks = append (tasks , r .ID )
1518+ }
1519+ }
1520+ for path , exist := range files {
1521+ if ! exist {
1522+ continue
1523+ }
1524+ err := utils .RemovePath (path , true )
1525+ if err != nil {
1526+ log .Error ("delete fail" , zap .Error (err ))
1527+ failNum += 1
1528+ }
1529+ }
1530+ if len (tasks ) > 0 {
1531+ err := qu .DelTasks (context .Background (), tasks )
1532+ if err != nil {
1533+ log .Error ("delete records fail" , zap .Error (err ))
1534+ }
1535+ }
1536+ return c .JSON (fiber.Map {
1537+ "success" : len (files ) - failNum ,
1538+ "fail" : failNum ,
1539+ })
1540+ }
1541+
14671542// handleUpdateNote 处理更新回测任务备注的请求
14681543func handleUpdateNote (c * fiber.Ctx ) error {
14691544 type UpdateNoteArgs struct {
0 commit comments