From 36d4fb9b2159db144711c92692df6033099efe59 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 22 Mar 2023 11:02:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=B6=E6=97=8F=E4=BF=AE=E6=94=B9=E9=93=AD?= =?UTF-8?q?=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/groupPower_m/family.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index 5125037..3489bf9 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -113,16 +113,23 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara if familyId == 0 || (name == "" && nameplate == "" && declaration == "" && icon == "") { return nil } + // 修改铭牌 + if nameplate != "" { + sql := "UPDATE `group_power` a left join (SELECT ? `id` FROM group_power WHERE nameplate = ?) b on a.id = b.id SET a.`nameplate`=? where a.id=? and b.id is null;" + result := model.Db.Exec(sql, familyId, nameplate, nameplate, familyId) + if result.Error != nil { + return myerr.WrapErr(result.Error) + } + if result.RowsAffected <= 0 { + return myerr.WrapErr(bizerr.GroupPowerHaveChangeInfo) + } + return nil + } db := model.Db.Model(GroupPower{}) updateMap := make(map[string]interface{}) if name != "" { updateMap["name"] = name } - if nameplate != "" { - updateMap["nameplate"] = nameplate - db = db.Joins("left join (SELECT ? `id` FROM group_power WHERE nameplate=?) b on a.id = b.id", familyId, nameplate). - Where("b.id is null") - } if declaration != "" { updateMap["declaration"] = declaration } -- 2.22.0