From ef26a2b8642600452ade66a97a93defaac78e553 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Tue, 5 May 2020 02:33:35 +0800 Subject: [PATCH] added batch delete action --- apis/system/config.go | 7 +++---- apis/system/dict/dictData.go | 9 +++------ apis/system/dict/dictType.go | 10 +++------- models/config.go | 9 +++++++++ models/dictData.go | 8 ++++++++ models/dictType.go | 8 ++++++++ 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/apis/system/config.go b/apis/system/config.go index c74b900b..c4440c9b 100644 --- a/apis/system/config.go +++ b/apis/system/config.go @@ -139,10 +139,9 @@ func UpdateConfig(c *gin.Context) { // @Router /api/v1/config/{configId} [delete] func DeleteConfig(c *gin.Context) { var data models.SysConfig - id, err := tools.StringToInt(c.Param("configId")) data.UpdateBy = tools.GetUserIdStr(c) - data.ConfigId = id - _, err = data.Delete() + IDS := tools.IdsStrToIdsIntGroup("configId", c) + result, err := data.BatchDelete(IDS) tools.HasError(err, "修改失败", 500) - app.OK(c, nil, msg.DeletedSuccess) + app.OK(c, result, msg.DeletedSuccess) } diff --git a/apis/system/dict/dictData.go b/apis/system/dict/dictData.go index 00a29cab..84c99506 100644 --- a/apis/system/dict/dictData.go +++ b/apis/system/dict/dictData.go @@ -144,12 +144,9 @@ func UpdateDictData(c *gin.Context) { // @Router /api/v1/dict/data/{dictCode} [delete] func DeleteDictData(c *gin.Context) { var data models.DictData - id, err := tools.StringToInt(c.Param("dictCode")) data.UpdateBy = tools.GetUserIdStr(c) - _, err = data.Delete(id) + IDS := tools.IdsStrToIdsIntGroup("dictCode", c) + result, err := data.BatchDelete(IDS) tools.HasError(err, "修改失败", 500) - - var res app.Response - res.Msg = "删除成功" - c.JSON(http.StatusOK, res.ReturnOK()) + app.OK(c,result,"删除成功") } diff --git a/apis/system/dict/dictType.go b/apis/system/dict/dictType.go index c7d2b193..4cc87c5d 100644 --- a/apis/system/dict/dictType.go +++ b/apis/system/dict/dictType.go @@ -136,13 +136,9 @@ func UpdateDictType(c *gin.Context) { // @Router /api/v1/dict/type/{dictId} [delete] func DeleteDictType(c *gin.Context) { var data models.DictType - id, err := tools.StringToInt(c.Param("dictId")) data.UpdateBy = tools.GetUserIdStr(c) - _, err = data.Delete(id) + IDS := tools.IdsStrToIdsIntGroup("dictId", c) + result, err := data.BatchDelete(IDS) tools.HasError(err, "修改失败", 500) - - c.JSON(http.StatusOK, gin.H{ - "code": 200, - "message": "删除成功", - }) + app.OK(c, result, "删除成功") } diff --git a/models/config.go b/models/config.go index cb8a19ba..b0cd54c4 100644 --- a/models/config.go +++ b/models/config.go @@ -105,3 +105,12 @@ func (e *SysConfig) Delete() (success bool, err error) { success = true return } + +func (e *SysConfig) BatchDelete(id []int) (Result bool, err error) { + if err = orm.Eloquent.Table(e.TableName()).Where("config_id in (?)", id).Delete(&SysConfig{}).Error; err != nil { + return + } + Result = true + return +} + diff --git a/models/dictData.go b/models/dictData.go index 16b8be4d..b945eb38 100644 --- a/models/dictData.go +++ b/models/dictData.go @@ -131,3 +131,11 @@ func (e *DictData) Delete(id int) (success bool, err error) { success = true return } + +func (e *DictData) BatchDelete(id []int) (Result bool, err error) { + if err = orm.Eloquent.Table(e.TableName()).Where("dict_code in (?)", id).Delete(&DictData{}).Error; err != nil { + return + } + Result = true + return +} diff --git a/models/dictType.go b/models/dictType.go index 7235fa06..1586e04e 100644 --- a/models/dictType.go +++ b/models/dictType.go @@ -119,3 +119,11 @@ func (e *DictType) Delete(id int) (success bool, err error) { success = true return } + +func (e *DictType) BatchDelete(id []int) (Result bool, err error) { + if err = orm.Eloquent.Table(e.TableName()).Where("dict_id in (?)", id).Delete(&DictType{}).Error; err != nil { + return + } + Result = true + return +} \ No newline at end of file