作者 tangxuhui

修改批量删除字典功能

... ... @@ -8,7 +8,7 @@ import (
type RemoveDictionaryCommand struct {
// 字典编号 主键
DictionaryId int `json:"dictionaryId" valid:"Required"`
DictionaryIds []int `json:"dictionaryIds" valid:"Required"`
}
func (removeDictionaryCommand *RemoveDictionaryCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -174,21 +174,27 @@ func (dictionaryService *DictionaryService) RemoveDictionary(removeDictionaryCom
} else {
dictionaryRepository = value
}
dictionary, err := dictionaryRepository.FindOne(map[string]interface{}{"dictionaryId": removeDictionaryCommand.DictionaryId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dictionary == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", removeDictionaryCommand.DictionaryId))
}
if dictionary, err := dictionaryRepository.Remove(dictionary); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
for _, dictionaryId := range removeDictionaryCommand.DictionaryIds {
if dictionaryId == 0 {
continue
}
dictionary, err := dictionaryRepository.FindOne(map[string]interface{}{"dictionaryId": dictionaryId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dictionary == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", dictionaryId))
}
if _, err := dictionaryRepository.Remove(dictionary); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return dictionary, nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return removeDictionaryCommand, nil
}
// 更新数据字典设置
... ...
... ... @@ -63,3 +63,11 @@ func (controller *DictionaryController) GetDictionaryByCode() {
data, err := dictionaryService.GetDictionaryByCode(getDictionaryQuery)
controller.Response(data, err)
}
func (controller *DictionaryController) RemoveDictionary() {
dictionaryService := service.NewDictionaryService(nil)
removeDictionaryCommand := &command.RemoveDictionaryCommand{}
_ = controller.Unmarshal(removeDictionaryCommand)
data, err := dictionaryService.RemoveDictionary(removeDictionaryCommand)
controller.Response(data, err)
}
... ...
... ... @@ -11,4 +11,5 @@ func init() {
web.Router("/dictionarys/:dictionaryId", &controllers.DictionaryController{}, "Get:GetDictionary")
web.Router("/dictionarys/search", &controllers.DictionaryController{}, "Post:ListDictionary")
web.Router("/dictionarys/dictionary-code", &controllers.DictionaryController{}, "Post:GetDictionaryByCode")
web.Router("/dictionarys/remove", &controllers.DictionaryController{}, "Post:RemoveDictionary")
}
... ...