diff --git a/handler/anchor_point_replace.go b/handler/anchor_point_replace.go index f113d05..57ee15b 100644 --- a/handler/anchor_point_replace.go +++ b/handler/anchor_point_replace.go @@ -1,3 +1,4 @@ +// Package handler provides HTTP handlers for various endpoints. package handler import ( diff --git a/handler/circuit_diagram_create.go b/handler/circuit_diagram_create.go index 5a0960a..9b19541 100644 --- a/handler/circuit_diagram_create.go +++ b/handler/circuit_diagram_create.go @@ -1,3 +1,4 @@ +// Package handler provides HTTP handlers for various endpoints. package handler import ( diff --git a/handler/circuit_diagram_delete.go b/handler/circuit_diagram_delete.go index 7e00c85..b2c8c3e 100644 --- a/handler/circuit_diagram_delete.go +++ b/handler/circuit_diagram_delete.go @@ -1,3 +1,4 @@ +// Package handler provides HTTP handlers for various endpoints. package handler import ( @@ -17,6 +18,7 @@ import ( "github.com/gin-gonic/gin" "github.com/gofrs/uuid" "go.uber.org/zap" + "gorm.io/gorm/clause" ) // CircuitDiagramDeleteHandler define circuit diagram delete process API @@ -142,8 +144,29 @@ func CircuitDiagramDeleteHandler(c *gin.Context) { } - component := &orm.Component{GlobalUUID: globalUUID} - result := tx.WithContext(cancelCtx).Delete(component) + var component orm.Component + result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Where("uuid = ?", globalUUID).Find(&component) + if result.Error != nil || result.RowsAffected == 0 { + tx.Rollback() + + err := result.Error + if result.RowsAffected == 0 { + err = fmt.Errorf("%w:please check uuid conditions", constant.ErrDeleteRowZero) + } + + logger.Error("query component info into postgresDB failed", zap.String("component_global_uuid", componentInfo.UUID), zap.Error(err)) + header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()} + resp := network.FailureResponse{ + FailResponseHeader: header, + PayLoad: map[string]interface{}{ + "uuid": componentInfo.UUID, + }, + } + c.JSON(http.StatusOK, resp) + return + } + + result = tx.WithContext(cancelCtx).Delete(component) if result.Error != nil || result.RowsAffected == 0 { tx.Rollback() @@ -164,7 +187,6 @@ func CircuitDiagramDeleteHandler(c *gin.Context) { return } - // TODO 增加 for update 操作后再删除 modelStruct := model.SelectModelByType(component.ComponentType) modelStruct.SetComponentID(component.ID) result = tx.WithContext(cancelCtx).Delete(modelStruct) diff --git a/handler/circuit_diagram_load.go b/handler/circuit_diagram_load.go index aa3ae1b..e1dbaf9 100644 --- a/handler/circuit_diagram_load.go +++ b/handler/circuit_diagram_load.go @@ -1,3 +1,4 @@ +// Package handler provides HTTP handlers for various endpoints. package handler import ( diff --git a/handler/circuit_diagram_update.go b/handler/circuit_diagram_update.go index c622190..8792b86 100644 --- a/handler/circuit_diagram_update.go +++ b/handler/circuit_diagram_update.go @@ -1,3 +1,4 @@ +// Package handler provides HTTP handlers for various endpoints. package handler import (