diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index 512503716d996632570c30cb166c63e9fe0271b8..3489bf904010d9bae39f63fb28bd640b24280695 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 }