@title RemoveWorkspace @description 删除工作区 @auth jasonchen @param workspaceId int "工作区id" @return error
(workspaceId int)
| 452 | // @param workspaceId int "工作区id" |
| 453 | // @return error |
| 454 | func RemoveWorkspace(workspaceId int) error { |
| 455 | db := getDb() |
| 456 | defer db.Close() |
| 457 | |
| 458 | // 数据校验 |
| 459 | var count int |
| 460 | row := db.QueryRow("select count(1) from workspace where w_id=? and w_is_del = 0", workspaceId) |
| 461 | switch err := row.Scan(&count); err { |
| 462 | case sql.ErrNoRows: |
| 463 | msg := fmt.Sprintf(" workspace (%v) ", workspaceId) |
| 464 | common.SmartIDELog.WarningF(i18nInstance.Common.Warn_dal_record_not_exit_condition, msg) |
| 465 | case nil: |
| 466 | if count <= 0 { |
| 467 | return errors.New(i18nInstance.Common.Warn_dal_record_not_exit) |
| 468 | } else if count > 1 { |
| 469 | return errors.New(i18nInstance.Common.Err_dal_update_count_too_much) |
| 470 | } |
| 471 | default: |
| 472 | panic(err) |
| 473 | } |
| 474 | |
| 475 | // |
| 476 | stmt, err := db.Prepare("update workspace set w_is_del=1 where (w_id=?) and w_is_del = 0") |
| 477 | if err != nil { |
| 478 | return err |
| 479 | } |
| 480 | res, err := stmt.Exec(workspaceId) |
| 481 | if err != nil { |
| 482 | return err |
| 483 | } |
| 484 | affect, err := res.RowsAffected() |
| 485 | if err != nil { |
| 486 | return err |
| 487 | } |
| 488 | |
| 489 | // |
| 490 | if affect != 1 { |
| 491 | if affect <= 0 { |
| 492 | return errors.New(i18nInstance.Common.Err_dal_update_fail) // 更新失败 |
| 493 | } else if affect > 1 { |
| 494 | common.SmartIDELog.Warning(i18nInstance.Common.Err_dal_update_count_too_much) // 更新条目 > 1 |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | return nil |
| 499 | } |