fix bug of create、delete、update handler
This commit is contained in:
parent
c1691d4da2
commit
d89bf83f8b
|
|
@ -4,6 +4,7 @@ package database
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
|
|
@ -26,9 +27,9 @@ func CreateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo netwo
|
|||
|
||||
component := orm.Component{
|
||||
GlobalUUID: globalUUID,
|
||||
GridID: componentInfo.GridID,
|
||||
ZoneID: componentInfo.ZoneID,
|
||||
StationID: componentInfo.StationID,
|
||||
GridID: strconv.FormatInt(componentInfo.GridID, 10),
|
||||
ZoneID: strconv.FormatInt(componentInfo.ZoneID, 10),
|
||||
StationID: strconv.FormatInt(componentInfo.StationID, 10),
|
||||
PageID: componentInfo.PageID,
|
||||
Tag: componentInfo.Tag,
|
||||
ComponentType: componentInfo.ComponentType,
|
||||
|
|
@ -39,7 +40,6 @@ func CreateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo netwo
|
|||
}
|
||||
|
||||
result := tx.WithContext(cancelCtx).Create(&component)
|
||||
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ package database
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
|
|
@ -24,11 +25,21 @@ func UpdateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo netwo
|
|||
return -1, fmt.Errorf("format uuid from string type failed:%w", err)
|
||||
}
|
||||
|
||||
component := orm.Component{
|
||||
var component orm.Component
|
||||
result := tx.Model(&orm.Component{}).WithContext(cancelCtx).Where("global_uuid = ?", globalUUID).Find(&component)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check update component conditions", constant.ErrUpdateRowZero)
|
||||
}
|
||||
return -1, fmt.Errorf("query component info failed:%w", err)
|
||||
}
|
||||
|
||||
updateParams := orm.Component{
|
||||
GlobalUUID: globalUUID,
|
||||
GridID: componentInfo.GridID,
|
||||
ZoneID: componentInfo.ZoneID,
|
||||
StationID: componentInfo.StationID,
|
||||
GridID: strconv.FormatInt(componentInfo.GridID, 10),
|
||||
ZoneID: strconv.FormatInt(componentInfo.ZoneID, 10),
|
||||
StationID: strconv.FormatInt(componentInfo.StationID, 10),
|
||||
PageID: componentInfo.PageID,
|
||||
Tag: componentInfo.Tag,
|
||||
ComponentType: componentInfo.ComponentType,
|
||||
|
|
@ -38,7 +49,8 @@ func UpdateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo netwo
|
|||
Ts: time.Now(),
|
||||
}
|
||||
|
||||
result := tx.Model(&orm.Component{}).WithContext(cancelCtx).Updates(&component)
|
||||
result = tx.Model(&orm.Component{}).WithContext(cancelCtx).Where("id = ?", component.ID).Updates(&updateParams)
|
||||
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
|
|
@ -46,6 +58,5 @@ func UpdateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo netwo
|
|||
}
|
||||
return -1, fmt.Errorf("update component info failed:%w", err)
|
||||
}
|
||||
|
||||
return component.ID, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +1,37 @@
|
|||
{
|
||||
"page_id":1,
|
||||
"topologics":[
|
||||
"page_id": 1,
|
||||
"topologics": [
|
||||
{
|
||||
"uuid_from":"12311-111",
|
||||
"uuid_to":"12311-114"
|
||||
"uuid_from": "70c190f2-8a60-42a9-b143-ec5f87e0aa6b",
|
||||
"uuid_to": "70c190f2-8a75-42a9-b166-ec5f87e0aa6b"
|
||||
},
|
||||
{
|
||||
"uuid_from":"12311-115",
|
||||
"uuid_to":"12311-116"
|
||||
"uuid_from": "70c190f2-8a75-42a9-b166-ec5f87e0aa6b",
|
||||
"uuid_to": "70c200f2-8a75-42a9-c166-bf5f87e0aa6b"
|
||||
}
|
||||
],
|
||||
"free_vertexs":[
|
||||
"12311-111",
|
||||
"12311-112",
|
||||
"12311-115"
|
||||
],
|
||||
"component_infos":[
|
||||
"component_infos": [
|
||||
{
|
||||
"grid_id":1,
|
||||
"zone":1,
|
||||
"station_id":1,
|
||||
"uuid":"12311-114",
|
||||
"name":"母线 1",
|
||||
"component_type":1,
|
||||
"in_service":true,
|
||||
"connected_bus":1,
|
||||
"state":1,
|
||||
"visible_id":"",
|
||||
"description":"",
|
||||
"context":"",
|
||||
"comment":"",
|
||||
"params":""
|
||||
"component_type": 3,
|
||||
"grid_id": 1,
|
||||
"name": "demo21",
|
||||
"page_id": 1,
|
||||
"station_id": 1,
|
||||
"uuid": "70c190f2-8a75-42a9-b166-ec5f87e0aa6b",
|
||||
"zone_id": 1,
|
||||
"context":"{\"top\":\"7.4\",\"left\":\"3.2\",\"right\":\"3.5\",\"buttom\":\"1.2\"}",
|
||||
"params": "{\"anchor_i\":false,\"anchor_v\":true,\"context\":\"{\\\"top\\\": \\\"7.4\\\", \\\"left\\\": \\\"3.2\\\", \\\"right\\\": \\\"3.5\\\", \\\"buttom\\\": \\\"1.2\\\"}\",\"name\":\"demo21\",\"oi_alarm\":110,\"op\":1,\"ov_alarm\":110,\"resistance\":100,\"ts\":\"2021-01-01T08:00:00+08:00\",\"ui_alarm\":90,\"uv_alarm\":90}"
|
||||
},
|
||||
{
|
||||
"grid_id":1,
|
||||
"zone":1,
|
||||
"station_id":1,
|
||||
"uuid":"12311-116",
|
||||
"name":"发电机 1",
|
||||
"component_type":1,
|
||||
"in_service":true,
|
||||
"connected_bus":1,
|
||||
"state":1,
|
||||
"visible_id":"",
|
||||
"description":"",
|
||||
"context":"",
|
||||
"comment":"",
|
||||
"params":""
|
||||
"component_type": 3,
|
||||
"grid_id": 1,
|
||||
"name": "demo22",
|
||||
"page_id": 1,
|
||||
"station_id": 1,
|
||||
"uuid": "70c200f2-8a75-42a9-c166-bf5f87e0aa6b",
|
||||
"zone_id": 1,
|
||||
"context":"{\"top\":\"7.4\",\"left\":\"3.2\",\"right\":\"3.5\",\"buttom\":\"1.2\"}",
|
||||
"params": "{\"anchor_i\":false,\"anchor_v\":true,\"context\":\"{\\\"top\\\": \\\"7.4\\\", \\\"left\\\": \\\"3.2\\\", \\\"right\\\": \\\"3.5\\\", \\\"buttom\\\": \\\"1.2\\\"}\",\"name\":\"demo22\",\"oi_alarm\":110,\"op\":1,\"ov_alarm\":110,\"resistance\":100,\"ts\":\"2021-01-01T08:00:00+08:00\",\"ui_alarm\":90,\"uv_alarm\":90}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -2,27 +2,22 @@
|
|||
"page_id":1,
|
||||
"topologics":[
|
||||
{
|
||||
"uuid_from":"12311-111",
|
||||
"uuid_to":"12311-114"
|
||||
"uuid_from": "70c190f2-8a75-42a9-b166-ec5f87e0aa6b",
|
||||
"uuid_to": "70c200f2-8a75-42a9-c166-bf5f87e0aa6b"
|
||||
},
|
||||
{
|
||||
"uuid_from":"12311-115",
|
||||
"uuid_to":"12311-116"
|
||||
"uuid_from": "70c190f2-8a60-42a9-b143-ec5f87e0aa6b",
|
||||
"uuid_to": "70c190f2-8a75-42a9-b166-ec5f87e0aa6b"
|
||||
}
|
||||
],
|
||||
"free_vertexs":[
|
||||
"12311-111",
|
||||
"12311-112",
|
||||
"12311-115"
|
||||
],
|
||||
"component_infos":[
|
||||
{
|
||||
"uuid":"12311-114",
|
||||
"component_type":1
|
||||
"uuid":"70c200f2-8a75-42a9-c166-bf5f87e0aa6b",
|
||||
"component_type":3
|
||||
},
|
||||
{
|
||||
"uuid":"12311-116",
|
||||
"component_type":1
|
||||
"uuid":"70c190f2-8a75-42a9-b166-ec5f87e0aa6b",
|
||||
"component_type":3
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,63 +3,23 @@
|
|||
"topologics":[
|
||||
{
|
||||
"change_type":1,
|
||||
"old_uuid_from":"12311-111",
|
||||
"old_uuid_to":"12311-113",
|
||||
"new_uuid_from":"12311-111",
|
||||
"new_uuid_to":"12311-114"
|
||||
},
|
||||
{
|
||||
"change_type":2,
|
||||
"old_uuid_from":"12311-111",
|
||||
"old_uuid_to":"12311-113",
|
||||
"new_uuid_from":"12311-112",
|
||||
"new_uuid_to":"12311-113"
|
||||
},
|
||||
{
|
||||
"change_type":3,
|
||||
"old_uuid_from":"",
|
||||
"old_uuid_to":"",
|
||||
"new_uuid_from":"12311-115",
|
||||
"new_uuid_to":"12311-116"
|
||||
"old_uuid_from":"70c190f2-8a75-42a9-b166-ec5f87e0aa6b",
|
||||
"old_uuid_to":"70c200f2-8a75-42a9-c166-bf5f87e0aa6b",
|
||||
"new_uuid_from":"e32bc0be-67f4-4d79-a5da-eaa40a5bd77d",
|
||||
"new_uuid_to":"70c200f2-8a75-42a9-c166-bf5f87e0aa6b"
|
||||
}
|
||||
],
|
||||
"free_vertexs":[
|
||||
"12311-111",
|
||||
"12311-112",
|
||||
"12311-115"
|
||||
],
|
||||
"component_infos":[
|
||||
"component_infos": [
|
||||
{
|
||||
"grid_id":1,
|
||||
"zone":1,
|
||||
"station_id":1,
|
||||
"uuid":"12311-114",
|
||||
"name":"母线 1",
|
||||
"component_type":1,
|
||||
"in_service":true,
|
||||
"connected_bus":1,
|
||||
"state":1,
|
||||
"visible_id":"",
|
||||
"description":"",
|
||||
"context":"",
|
||||
"comment":"",
|
||||
"params":""
|
||||
},
|
||||
{
|
||||
"grid_id":1,
|
||||
"zone":1,
|
||||
"station_id":1,
|
||||
"uuid":"12311-116",
|
||||
"name":"发电机 1",
|
||||
"component_type":1,
|
||||
"in_service":true,
|
||||
"connected_bus":1,
|
||||
"state":1,
|
||||
"visible_id":"",
|
||||
"description":"",
|
||||
"context":"",
|
||||
"comment":"",
|
||||
"params":""
|
||||
"component_type": 3,
|
||||
"grid_id": 1,
|
||||
"name": "demo23",
|
||||
"page_id": 1,
|
||||
"station_id": 1,
|
||||
"uuid": "70c200f2-8a75-42a9-c166-bf5f87e0aa6b",
|
||||
"zone_id": 1,
|
||||
"context":"{\"top\":\"7.4\",\"left\":\"3.2\",\"right\":\"3.5\",\"buttom\":\"1.2\"}",
|
||||
"params": "{\"anchor_i\":false,\"anchor_v\":true,\"context\":\"{\\\"top\\\": \\\"7.4\\\", \\\"left\\\": \\\"3.2\\\", \\\"right\\\": \\\"3.5\\\", \\\"buttom\\\": \\\"1.2\\\"}\",\"name\":\"demo23\",\"oi_alarm\":110,\"op\":1,\"ov_alarm\":110,\"resistance\":100,\"ts\":\"2021-01-01T08:00:00+08:00\",\"ui_alarm\":90,\"uv_alarm\":90}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ func ComponentAnchorReplaceHandler(c *gin.Context) {
|
|||
|
||||
anchorParam := config.AnchorParamConfig{
|
||||
AnchorParamBaseConfig: config.AnchorParamBaseConfig{
|
||||
StationID: strconv.FormatInt(componentInfo.StationID, 10),
|
||||
StationID: componentInfo.StationID,
|
||||
ComponentID: strconv.FormatInt(componentInfo.ID, 10),
|
||||
UUID: uuid,
|
||||
AnchorName: anchorName,
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
}
|
||||
|
||||
var component orm.Component
|
||||
result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Where("uuid = ?", globalUUID).Find(&component)
|
||||
result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Where("global_uuid = ?", globalUUID).Find(&component)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
tx.Rollback()
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
|
||||
modelStruct := model.SelectModelByType(component.ComponentType)
|
||||
modelStruct.SetComponentID(component.ID)
|
||||
result = tx.WithContext(cancelCtx).Delete(modelStruct)
|
||||
result = tx.WithContext(cancelCtx).Where("component_id = ?", component.ID).Delete(modelStruct)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
tx.Rollback()
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ type CircuitDiagramUpdateRequest struct {
|
|||
// ParseUUID define parse UUID by change type in topologic change struct
|
||||
func ParseUUID(info TopologicChangeInfo) (TopologicUUIDChangeInfos, error) {
|
||||
var UUIDChangeInfo TopologicUUIDChangeInfos
|
||||
UUIDChangeInfo.ChangeType = info.ChangeType
|
||||
|
||||
switch info.ChangeType {
|
||||
case constant.UUIDFromChangeType:
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ type Component struct {
|
|||
ID int64 `gorm:"column:id;primaryKey"`
|
||||
GlobalUUID uuid.UUID `gorm:"column:global_uuid"`
|
||||
Tag string `gorm:"column:tag"`
|
||||
GridID int64 `gorm:"column:grid"`
|
||||
ZoneID int64 `gorm:"column:zone"`
|
||||
StationID int64 `gorm:"column:station"`
|
||||
GridID string `gorm:"column:grid"`
|
||||
ZoneID string `gorm:"column:zone"`
|
||||
StationID string `gorm:"column:station"`
|
||||
PageID int64 `gorm:"column:page_id"`
|
||||
ComponentType int `gorm:"column:type"`
|
||||
Name string `gorm:"column:name"`
|
||||
|
|
|
|||
22
orm/demo.go
22
orm/demo.go
|
|
@ -4,17 +4,17 @@ package orm
|
|||
import "time"
|
||||
|
||||
type Demo struct {
|
||||
ID int64 `gorm:"column:id"` // 主键 ID
|
||||
ComponentID int64 `gorm:"column:component_id"` // compoent表ID
|
||||
Resistance float32 `gorm:"column:resistance"` // 电阻值
|
||||
AnchorV bool `gorm:"column:anchor_v"` // 是否锚定电压
|
||||
UVAlarm float32 `gorm:"column:uv_alarm"` // 欠压告警值
|
||||
OVAlarm float32 `gorm:"column:ov_alarm"` // 过压告警值
|
||||
AnchorI bool `gorm:"column:anchor_i"` // 是否锚定电流
|
||||
UIAlarm float32 `gorm:"column:ui_alarm"` // 低电流告警值
|
||||
OIAlarm float32 `gorm:"column:oi_alarm"` // 高电流告警值
|
||||
Op int `gorm:"column:op"` // 操作人 ID
|
||||
Ts time.Time `gorm:"column:ts"` // 操作时间
|
||||
ID int64 `gorm:"column:id" json:"id"` // 主键 ID
|
||||
ComponentID int64 `gorm:"column:component_id" json:"component_id"` // compoent表ID
|
||||
Resistance float32 `gorm:"column:resistance" json:"resistance"` // 电阻值
|
||||
AnchorV bool `gorm:"column:anchor_v" json:"anchor_v"` // 是否锚定电压
|
||||
UVAlarm float32 `gorm:"column:uv_alarm" json:"uv_alarm"` // 欠压告警值
|
||||
OVAlarm float32 `gorm:"column:ov_alarm" json:"ov_alarm"` // 过压告警值
|
||||
AnchorI bool `gorm:"column:anchor_i" json:"anchor_i"` // 是否锚定电流
|
||||
UIAlarm float32 `gorm:"column:ui_alarm" json:"ui_alarm"` // 低电流告警值
|
||||
OIAlarm float32 `gorm:"column:oi_alarm" json:"oi_alarm"` // 高电流告警值
|
||||
Op int `gorm:"column:op" json:"op"` // 操作人 ID
|
||||
Ts time.Time `gorm:"column:ts" json:"ts"` // 操作时间
|
||||
}
|
||||
|
||||
// TableName func respresent return table name of busbar section
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ var ParseFunc = func(parseConfig interface{}) {
|
|||
|
||||
anchorParam := config.AnchorParamConfig{
|
||||
AnchorParamBaseConfig: config.AnchorParamBaseConfig{
|
||||
StationID: strconv.FormatInt(modelParseConfig.ComponentInfo.StationID, 10),
|
||||
StationID: modelParseConfig.ComponentInfo.StationID,
|
||||
ComponentID: strconv.FormatInt(modelParseConfig.ComponentInfo.ID, 10),
|
||||
UUID: uuid,
|
||||
AnchorName: anchorName,
|
||||
|
|
|
|||
Loading…
Reference in New Issue