...
|
...
|
@@ -2,6 +2,7 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"sort"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
...
|
...
|
@@ -30,7 +31,25 @@ func (dictionaryService *DictionaryService) CreateDictionary(createDictionaryCom |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
newDictionary := &domain.Dictionary{} //TODO
|
|
|
|
|
|
var items []domain.DictionaryItem
|
|
|
for _, item := range createDictionaryCommand.DictItems {
|
|
|
i := domain.DictionaryItem{
|
|
|
ItemCode: item.ItemCode,
|
|
|
ItemLabel: item.ItemLabel,
|
|
|
ItemValue: item.ItemValue,
|
|
|
IsShow: item.IsShow,
|
|
|
Sort: item.Sort,
|
|
|
}
|
|
|
items = append(items, i)
|
|
|
}
|
|
|
sort.Sort(domain.DictionaryItems(items))
|
|
|
newDictionary := &domain.Dictionary{
|
|
|
DictCode: createDictionaryCommand.DictCode,
|
|
|
DictName: createDictionaryCommand.DictName,
|
|
|
Desc: createDictionaryCommand.Desc,
|
|
|
DictItems: items,
|
|
|
}
|
|
|
var dictionaryRepository domain.DictionaryRepository
|
|
|
if value, err := factory.CreateDictionaryRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -72,7 +91,14 @@ func (dictionaryService *DictionaryService) GetDictionary(getDictionaryQuery *qu |
|
|
} else {
|
|
|
dictionaryRepository = value
|
|
|
}
|
|
|
dictionary, err := dictionaryRepository.FindOne(map[string]interface{}{"dictionaryId": getDictionaryQuery.DictCode})
|
|
|
queryCondition := make(map[string]interface{})
|
|
|
if len(getDictionaryQuery.DictCode) > 0 {
|
|
|
queryCondition["dictCode"] = getDictionaryQuery.DictCode
|
|
|
}
|
|
|
if getDictionaryQuery.DictionaryId > 0 {
|
|
|
queryCondition["dictionaryId"] = getDictionaryQuery.DictCode
|
|
|
}
|
|
|
dictionary, err := dictionaryRepository.FindOne(queryCondition)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -150,7 +176,7 @@ func (dictionaryService *DictionaryService) RemoveDictionary(removeDictionaryCom |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dictionary == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeDictionaryCommand.DictionaryId)))
|
|
|
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())
|
...
|
...
|
@@ -190,9 +216,27 @@ func (dictionaryService *DictionaryService) UpdateDictionary(updateDictionaryCom |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dictionary == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDictionaryCommand.DictionaryId)))
|
|
|
}
|
|
|
if err := dictionary.Update(tool_funs.SimpleStructToMap(updateDictionaryCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", updateDictionaryCommand.DictionaryId))
|
|
|
}
|
|
|
var items []domain.DictionaryItem
|
|
|
for _, item := range updateDictionaryCommand.DictItems {
|
|
|
i := domain.DictionaryItem{
|
|
|
ItemCode: item.ItemCode,
|
|
|
ItemLabel: item.ItemLabel,
|
|
|
ItemValue: item.ItemValue,
|
|
|
IsShow: item.IsShow,
|
|
|
Sort: item.Sort,
|
|
|
}
|
|
|
items = append(items, i)
|
|
|
}
|
|
|
sort.Sort(domain.DictionaryItems(items))
|
|
|
err = dictionary.Update(map[string]interface{}{
|
|
|
"dictCode": updateDictionaryCommand.DictCode,
|
|
|
"dictName": updateDictionaryCommand.DictName,
|
|
|
"desc": updateDictionaryCommand.Desc,
|
|
|
"dictItems": items,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if dictionary, err := dictionaryRepository.Save(dictionary); err != nil {
|
...
|
...
|
|