作者 tangxuhui

修改批量删除字典功能

@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 8
9 type RemoveDictionaryCommand struct { 9 type RemoveDictionaryCommand struct {
10 // 字典编号 主键 10 // 字典编号 主键
11 - DictionaryId int `json:"dictionaryId" valid:"Required"` 11 + DictionaryIds []int `json:"dictionaryIds" valid:"Required"`
12 } 12 }
13 13
14 func (removeDictionaryCommand *RemoveDictionaryCommand) Valid(validation *validation.Validation) { 14 func (removeDictionaryCommand *RemoveDictionaryCommand) Valid(validation *validation.Validation) {
@@ -174,21 +174,27 @@ func (dictionaryService *DictionaryService) RemoveDictionary(removeDictionaryCom @@ -174,21 +174,27 @@ func (dictionaryService *DictionaryService) RemoveDictionary(removeDictionaryCom
174 } else { 174 } else {
175 dictionaryRepository = value 175 dictionaryRepository = value
176 } 176 }
177 - dictionary, err := dictionaryRepository.FindOne(map[string]interface{}{"dictionaryId": removeDictionaryCommand.DictionaryId})  
178 - if err != nil {  
179 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
180 - }  
181 - if dictionary == nil {  
182 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", removeDictionaryCommand.DictionaryId))  
183 - }  
184 - if dictionary, err := dictionaryRepository.Remove(dictionary); err != nil {  
185 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
186 - } else {  
187 - if err := transactionContext.CommitTransaction(); err != nil {  
188 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 177 + for _, dictionaryId := range removeDictionaryCommand.DictionaryIds {
  178 + if dictionaryId == 0 {
  179 + continue
  180 + }
  181 + dictionary, err := dictionaryRepository.FindOne(map[string]interface{}{"dictionaryId": dictionaryId})
  182 + if err != nil {
  183 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  184 + }
  185 + if dictionary == nil {
  186 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", dictionaryId))
  187 + }
  188 + if _, err := dictionaryRepository.Remove(dictionary); err != nil {
  189 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
189 } 190 }
190 - return dictionary, nil  
191 } 191 }
  192 +
  193 + if err := transactionContext.CommitTransaction(); err != nil {
  194 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  195 + }
  196 + return removeDictionaryCommand, nil
  197 +
192 } 198 }
193 199
194 // 更新数据字典设置 200 // 更新数据字典设置
@@ -63,3 +63,11 @@ func (controller *DictionaryController) GetDictionaryByCode() { @@ -63,3 +63,11 @@ func (controller *DictionaryController) GetDictionaryByCode() {
63 data, err := dictionaryService.GetDictionaryByCode(getDictionaryQuery) 63 data, err := dictionaryService.GetDictionaryByCode(getDictionaryQuery)
64 controller.Response(data, err) 64 controller.Response(data, err)
65 } 65 }
  66 +
  67 +func (controller *DictionaryController) RemoveDictionary() {
  68 + dictionaryService := service.NewDictionaryService(nil)
  69 + removeDictionaryCommand := &command.RemoveDictionaryCommand{}
  70 + _ = controller.Unmarshal(removeDictionaryCommand)
  71 + data, err := dictionaryService.RemoveDictionary(removeDictionaryCommand)
  72 + controller.Response(data, err)
  73 +}
@@ -11,4 +11,5 @@ func init() { @@ -11,4 +11,5 @@ func init() {
11 web.Router("/dictionarys/:dictionaryId", &controllers.DictionaryController{}, "Get:GetDictionary") 11 web.Router("/dictionarys/:dictionaryId", &controllers.DictionaryController{}, "Get:GetDictionary")
12 web.Router("/dictionarys/search", &controllers.DictionaryController{}, "Post:ListDictionary") 12 web.Router("/dictionarys/search", &controllers.DictionaryController{}, "Post:ListDictionary")
13 web.Router("/dictionarys/dictionary-code", &controllers.DictionaryController{}, "Post:GetDictionaryByCode") 13 web.Router("/dictionarys/dictionary-code", &controllers.DictionaryController{}, "Post:GetDictionaryByCode")
  14 + web.Router("/dictionarys/remove", &controllers.DictionaryController{}, "Post:RemoveDictionary")
14 } 15 }