作者 tangxuhui

字典curd功能实现

@@ -7,23 +7,44 @@ import ( @@ -7,23 +7,44 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
8 ) 8 )
9 9
  10 +type DictionaryItem struct {
  11 + // 项编码
  12 + ItemCode string `json:"itemCode" valid:"Required;MaxSize(30)"`
  13 + // 项标签
  14 + ItemLabel string `json:"itemLabel" valid:"Required;MaxSize(30)"`
  15 + // 值
  16 + ItemValue string `json:"itemValue" valid:"Required;MaxSize(30)"`
  17 + // 是否可见【1:不可以】【2:可以】
  18 + IsShow int `json:"isShow"`
  19 + // 显示序号
  20 + Sort int `json:"sort"`
  21 +}
  22 +
10 type CreateDictionaryCommand struct { 23 type CreateDictionaryCommand struct {
11 - // 字典编号 主键  
12 - DictionaryId int `json:"dictionaryId,omitempty"`  
13 // 字典编码 24 // 字典编码
14 - DictCode string `json:"dictCode,omitempty"` 25 + DictCode string `json:"dictCode" valid:"Required;MaxSize(30)"`
15 // 字典名称 26 // 字典名称
16 - DictName string `json:"dictName,omitempty"` 27 + DictName string `json:"dictName" valid:"Required;MaxSize(30)"`
17 // 备注信息 28 // 备注信息
18 - Desc string `json:"desc,omitempty"`  
19 - // 是否可见【1:不可以】【2:可以】  
20 - IsShow int `json:"isShow,omitempty"` 29 + Desc string `json:"desc" valid:"MaxSize(100)"`
21 // 字典值列表 30 // 字典值列表
22 - DictItems []*domain.DictionaryItem `json:"dictItems,omitempty"` 31 + DictItems []DictionaryItem `json:"dictItems"`
23 } 32 }
24 33
25 -func (createDictionaryCommand *CreateDictionaryCommand) Valid(validation *validation.Validation) {  
26 - validation.SetError("CustomValid", "未实现的自定义认证") 34 +// 实现了接口 validation.ValidFormer
  35 +func (createDictionaryCommand *CreateDictionaryCommand) Valid(v *validation.Validation) {
  36 + //检查items
  37 + sortmap := make(map[int]struct{})
  38 + for _, item := range createDictionaryCommand.DictItems {
  39 + if _, ok := sortmap[item.Sort]; ok {
  40 + v.SetError("Sort", "明细项顺序值重复")
  41 + }
  42 + sortmap[item.Sort] = struct{}{}
  43 + vOk := domain.DictionaryItemShow(item.IsShow).Valid()
  44 + if !vOk {
  45 + v.SetError("IsShow", "明细项是否显示值异常")
  46 + }
  47 + }
27 } 48 }
28 49
29 func (createDictionaryCommand *CreateDictionaryCommand) ValidateCommand() error { 50 func (createDictionaryCommand *CreateDictionaryCommand) ValidateCommand() error {
@@ -8,11 +8,11 @@ import ( @@ -8,11 +8,11 @@ import (
8 8
9 type RemoveDictionaryCommand struct { 9 type RemoveDictionaryCommand struct {
10 // 字典编号 主键 10 // 字典编号 主键
11 - DictionaryId int `json:"dictionaryId,omitempty"` 11 + DictionaryId int `json:"dictionaryId" valid:"Required"`
12 } 12 }
13 13
14 func (removeDictionaryCommand *RemoveDictionaryCommand) Valid(validation *validation.Validation) { 14 func (removeDictionaryCommand *RemoveDictionaryCommand) Valid(validation *validation.Validation) {
15 - validation.SetError("CustomValid", "未实现的自定义认证") 15 +
16 } 16 }
17 17
18 func (removeDictionaryCommand *RemoveDictionaryCommand) ValidateCommand() error { 18 func (removeDictionaryCommand *RemoveDictionaryCommand) ValidateCommand() error {
@@ -9,21 +9,32 @@ import ( @@ -9,21 +9,32 @@ import (
9 9
10 type UpdateDictionaryCommand struct { 10 type UpdateDictionaryCommand struct {
11 // 字典编号 主键 11 // 字典编号 主键
12 - DictionaryId int64 `json:"dictionaryId,omitempty"` 12 + DictionaryId int64 `json:"dictionaryId" valid:"Required"`
13 // 字典编码 13 // 字典编码
14 - DictCode string `json:"dictCode,omitempty"` 14 + DictCode string `json:"dictCode" valid:"Required;MaxSize(30)"`
15 // 字典名称 15 // 字典名称
16 - DictName string `json:"dictName,omitempty"` 16 + DictName string `json:"dictName" valid:"Required;MaxSize(30)"`
17 // 备注信息 17 // 备注信息
18 - Desc string `json:"desc,omitempty"` 18 + Desc string `json:"desc" valid:"Required;MaxSize(100)"`
19 // 是否可见【1:不可以】【2:可以】 19 // 是否可见【1:不可以】【2:可以】
20 - IsShow int `json:"isShow,omitempty"` 20 + IsShow int `json:"isShow"`
21 // 字典值列表 21 // 字典值列表
22 - DictItems []*domain.DictionaryItem `json:"dictItems,omitempty"` 22 + DictItems []DictionaryItem `json:"dictItems"`
23 } 23 }
24 24
25 -func (updateDictionaryCommand *UpdateDictionaryCommand) Valid(validation *validation.Validation) {  
26 - validation.SetError("CustomValid", "未实现的自定义认证") 25 +func (updateDictionaryCommand *UpdateDictionaryCommand) Valid(v *validation.Validation) {
  26 + //检查items
  27 + sortmap := make(map[int]struct{})
  28 + for _, item := range updateDictionaryCommand.DictItems {
  29 + if _, ok := sortmap[item.Sort]; ok {
  30 + v.SetError("sort", "明细项顺序值重复")
  31 + }
  32 + sortmap[item.Sort] = struct{}{}
  33 + vOk := domain.DictionaryItemShow(item.IsShow).Valid()
  34 + if !vOk {
  35 + v.SetError("IsShow", "明细项是否显示值异常")
  36 + }
  37 + }
27 } 38 }
28 39
29 func (updateDictionaryCommand *UpdateDictionaryCommand) ValidateCommand() error { 40 func (updateDictionaryCommand *UpdateDictionaryCommand) ValidateCommand() error {
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 type GetDictionaryQuery struct { 9 type GetDictionaryQuery struct {
10 // 字典编码 10 // 字典编码
11 DictionaryId int64 `json:"dictionaryId"` 11 DictionaryId int64 `json:"dictionaryId"`
12 - DictCode string `json:"dictCode,omitempty"` 12 + DictCode string `json:"dictCode"`
13 } 13 }
14 14
15 func (getDictionaryQuery *GetDictionaryQuery) Valid(validation *validation.Validation) { 15 func (getDictionaryQuery *GetDictionaryQuery) Valid(validation *validation.Validation) {
@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "sort"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
7 "github.com/linmadan/egglib-go/utils/tool_funs" 8 "github.com/linmadan/egglib-go/utils/tool_funs"
@@ -30,7 +31,25 @@ func (dictionaryService *DictionaryService) CreateDictionary(createDictionaryCom @@ -30,7 +31,25 @@ func (dictionaryService *DictionaryService) CreateDictionary(createDictionaryCom
30 defer func() { 31 defer func() {
31 transactionContext.RollbackTransaction() 32 transactionContext.RollbackTransaction()
32 }() 33 }()
33 - newDictionary := &domain.Dictionary{} //TODO 34 +
  35 + var items []domain.DictionaryItem
  36 + for _, item := range createDictionaryCommand.DictItems {
  37 + i := domain.DictionaryItem{
  38 + ItemCode: item.ItemCode,
  39 + ItemLabel: item.ItemLabel,
  40 + ItemValue: item.ItemValue,
  41 + IsShow: item.IsShow,
  42 + Sort: item.Sort,
  43 + }
  44 + items = append(items, i)
  45 + }
  46 + sort.Sort(domain.DictionaryItems(items))
  47 + newDictionary := &domain.Dictionary{
  48 + DictCode: createDictionaryCommand.DictCode,
  49 + DictName: createDictionaryCommand.DictName,
  50 + Desc: createDictionaryCommand.Desc,
  51 + DictItems: items,
  52 + }
34 var dictionaryRepository domain.DictionaryRepository 53 var dictionaryRepository domain.DictionaryRepository
35 if value, err := factory.CreateDictionaryRepository(map[string]interface{}{ 54 if value, err := factory.CreateDictionaryRepository(map[string]interface{}{
36 "transactionContext": transactionContext, 55 "transactionContext": transactionContext,
@@ -72,7 +91,14 @@ func (dictionaryService *DictionaryService) GetDictionary(getDictionaryQuery *qu @@ -72,7 +91,14 @@ func (dictionaryService *DictionaryService) GetDictionary(getDictionaryQuery *qu
72 } else { 91 } else {
73 dictionaryRepository = value 92 dictionaryRepository = value
74 } 93 }
75 - dictionary, err := dictionaryRepository.FindOne(map[string]interface{}{"dictionaryId": getDictionaryQuery.DictCode}) 94 + queryCondition := make(map[string]interface{})
  95 + if len(getDictionaryQuery.DictCode) > 0 {
  96 + queryCondition["dictCode"] = getDictionaryQuery.DictCode
  97 + }
  98 + if getDictionaryQuery.DictionaryId > 0 {
  99 + queryCondition["dictionaryId"] = getDictionaryQuery.DictCode
  100 + }
  101 + dictionary, err := dictionaryRepository.FindOne(queryCondition)
76 if err != nil { 102 if err != nil {
77 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 103 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
78 } 104 }
@@ -150,7 +176,7 @@ func (dictionaryService *DictionaryService) RemoveDictionary(removeDictionaryCom @@ -150,7 +176,7 @@ func (dictionaryService *DictionaryService) RemoveDictionary(removeDictionaryCom
150 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 176 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
151 } 177 }
152 if dictionary == nil { 178 if dictionary == nil {
153 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeDictionaryCommand.DictionaryId))) 179 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", removeDictionaryCommand.DictionaryId))
154 } 180 }
155 if dictionary, err := dictionaryRepository.Remove(dictionary); err != nil { 181 if dictionary, err := dictionaryRepository.Remove(dictionary); err != nil {
156 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 182 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -190,9 +216,27 @@ func (dictionaryService *DictionaryService) UpdateDictionary(updateDictionaryCom @@ -190,9 +216,27 @@ func (dictionaryService *DictionaryService) UpdateDictionary(updateDictionaryCom
190 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 216 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
191 } 217 }
192 if dictionary == nil { 218 if dictionary == nil {
193 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDictionaryCommand.DictionaryId)))  
194 - }  
195 - if err := dictionary.Update(tool_funs.SimpleStructToMap(updateDictionaryCommand)); err != nil { 219 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", updateDictionaryCommand.DictionaryId))
  220 + }
  221 + var items []domain.DictionaryItem
  222 + for _, item := range updateDictionaryCommand.DictItems {
  223 + i := domain.DictionaryItem{
  224 + ItemCode: item.ItemCode,
  225 + ItemLabel: item.ItemLabel,
  226 + ItemValue: item.ItemValue,
  227 + IsShow: item.IsShow,
  228 + Sort: item.Sort,
  229 + }
  230 + items = append(items, i)
  231 + }
  232 + sort.Sort(domain.DictionaryItems(items))
  233 + err = dictionary.Update(map[string]interface{}{
  234 + "dictCode": updateDictionaryCommand.DictCode,
  235 + "dictName": updateDictionaryCommand.DictName,
  236 + "desc": updateDictionaryCommand.Desc,
  237 + "dictItems": items,
  238 + })
  239 + if err != nil {
196 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 240 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
197 } 241 }
198 if dictionary, err := dictionaryRepository.Save(dictionary); err != nil { 242 if dictionary, err := dictionaryRepository.Save(dictionary); err != nil {
  1 +package constant
  2 +
  3 +var ValidationMessageTmpls = map[string]string{
  4 + "Required": "不能为空",
  5 + "Min": "最小值: %d",
  6 + "Max": "最大值: %d",
  7 + "Range": "数值的范围 %d - %d",
  8 + "MinSize": "最小长度: %d",
  9 + "MaxSize": "最大长度: %d",
  10 + "Length": "指定长度: %d",
  11 + "Alpha": "必须为有效的字母字符",
  12 + "Numeric": "必须为有效的数字",
  13 + "AlphaNumeric": "必须为有效的字母或数字",
  14 + "Match": "必须匹配 %s",
  15 + "NoMatch": "必须不匹配 %s",
  16 + "AlphaDash": "必须为字母、数字或横杠(-_)",
  17 + "Email": "必须为邮箱格式",
  18 + "IP": "必须为有效的IP格式",
  19 + "Base64": "必须为有效的base64字符",
  20 + "Mobile": "必须有效的手机号码",
  21 + "Tel": "必须是有效的电话号码",
  22 + "Phone": "必须是有效的电话或手机号码",
  23 + "ZipCode": "必须是有效的邮政编码",
  24 +}
@@ -10,10 +10,8 @@ type Dictionary struct { @@ -10,10 +10,8 @@ type Dictionary struct {
10 DictName string `json:"dictName"` 10 DictName string `json:"dictName"`
11 // 备注信息 11 // 备注信息
12 Desc string `json:"desc"` 12 Desc string `json:"desc"`
13 - // 是否可见【1:不可以】【2:可以】  
14 - IsShow int `json:"isShow"`  
15 // 字典值列表 13 // 字典值列表
16 - DictItems []*DictionaryItem `json:"dictItems"` 14 + DictItems []DictionaryItem `json:"dictItems"`
17 } 15 }
18 16
19 type DictionaryRepository interface { 17 type DictionaryRepository interface {
@@ -43,11 +41,8 @@ func (dictionary *Dictionary) Update(data map[string]interface{}) error { @@ -43,11 +41,8 @@ func (dictionary *Dictionary) Update(data map[string]interface{}) error {
43 if desc, ok := data["desc"]; ok { 41 if desc, ok := data["desc"]; ok {
44 dictionary.Desc = desc.(string) 42 dictionary.Desc = desc.(string)
45 } 43 }
46 - if isShow, ok := data["isShow"]; ok {  
47 - dictionary.IsShow = isShow.(int)  
48 - }  
49 if dictItems, ok := data["dictItems"]; ok { 44 if dictItems, ok := data["dictItems"]; ok {
50 - dictionary.DictItems = dictItems.([]*DictionaryItem) 45 + dictionary.DictItems = dictItems.([]DictionaryItem)
51 } 46 }
52 return nil 47 return nil
53 } 48 }
@@ -8,8 +8,35 @@ type DictionaryItem struct { @@ -8,8 +8,35 @@ type DictionaryItem struct {
8 ItemLabel string `json:"itemLabel"` 8 ItemLabel string `json:"itemLabel"`
9 // 值 9 // 值
10 ItemValue string `json:"itemValue"` 10 ItemValue string `json:"itemValue"`
11 - // 启用状态(启用:1 禁用:2)  
12 - EnableStatus string `json:"enableStatus"` 11 + // 是否可见【1:不可以】【2:可以】
  12 + IsShow int `json:"isShow"`
13 // 显示序号 13 // 显示序号
14 Sort int `json:"sort"` 14 Sort int `json:"sort"`
15 } 15 }
  16 +
  17 +type DictionaryItemShow int
  18 +
  19 +const (
  20 + DictionaryItemIsShow int = 1 //不可见
  21 + DictionaryItemNotShow int = 2 //可见
  22 +)
  23 +
  24 +func (show DictionaryItemShow) Valid() bool {
  25 + var ok bool
  26 + switch int(show) {
  27 + case DictionaryItemNotShow:
  28 + ok = true
  29 + case DictionaryItemIsShow:
  30 + ok = true
  31 + default:
  32 + ok = false
  33 + }
  34 + return ok
  35 +}
  36 +
  37 +//明细项排序
  38 +type DictionaryItems []DictionaryItem
  39 +
  40 +func (a DictionaryItems) Len() int { return len(a) }
  41 +func (a DictionaryItems) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  42 +func (a DictionaryItems) Less(i, j int) bool { return a[i].Sort < a[j].Sort }
@@ -17,5 +17,5 @@ type Dictionary struct { @@ -17,5 +17,5 @@ type Dictionary struct {
17 // 是否可见【1:不可以】【2:可以】 17 // 是否可见【1:不可以】【2:可以】
18 IsShow int 18 IsShow int
19 // 字典值列表 19 // 字典值列表
20 - DictItems []*domain.DictionaryItem `pg:",array"` 20 + DictItems []domain.DictionaryItem `pg:",array"`
21 } 21 }
@@ -11,7 +11,6 @@ func TransformToDictionaryDomainModelFromPgModels(dictionaryModel *models.Dictio @@ -11,7 +11,6 @@ func TransformToDictionaryDomainModelFromPgModels(dictionaryModel *models.Dictio
11 DictCode: dictionaryModel.DictCode, 11 DictCode: dictionaryModel.DictCode,
12 DictName: dictionaryModel.DictName, 12 DictName: dictionaryModel.DictName,
13 Desc: dictionaryModel.Desc, 13 Desc: dictionaryModel.Desc,
14 - IsShow: dictionaryModel.IsShow,  
15 DictItems: dictionaryModel.DictItems, 14 DictItems: dictionaryModel.DictItems,
16 }, nil 15 }, nil
17 } 16 }
  1 +package repository
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/utils/snowflake"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/log"
  6 +)
  7 +
  8 +var idWorker *snowflake.IdWorker
  9 +
  10 +func init() {
  11 + worker, err := snowflake.NewIdWorker(1)
  12 + if err != nil {
  13 + log.Logger.Panic("idWorker init err" + err.Error())
  14 + return
  15 + }
  16 + idWorker = worker
  17 +}
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 "github.com/go-pg/pg/v10" 6 "github.com/go-pg/pg/v10"
7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
9 - "github.com/linmadan/egglib-go/utils/snowflake" 9 +
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform"
@@ -17,20 +17,16 @@ type DictionaryRepository struct { @@ -17,20 +17,16 @@ type DictionaryRepository struct {
17 } 17 }
18 18
19 func (repository *DictionaryRepository) nextIdentify() (int64, error) { 19 func (repository *DictionaryRepository) nextIdentify() (int64, error) {
20 - IdWorker, err := snowflake.NewIdWorker(1)  
21 - if err != nil {  
22 - return 0, err  
23 - }  
24 - id, err := IdWorker.NextId() 20 + id, err := idWorker.NextId()
25 return id, err 21 return id, err
26 } 22 }
  23 +
27 func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*domain.Dictionary, error) { 24 func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*domain.Dictionary, error) {
28 sqlBuildFields := []string{ 25 sqlBuildFields := []string{
29 "dictionary_id", 26 "dictionary_id",
30 "dict_code", 27 "dict_code",
31 "dict_name", 28 "dict_name",
32 "desc", 29 "desc",
33 - "is_show",  
34 "dict_items", 30 "dict_items",
35 } 31 }
36 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 32 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
@@ -52,7 +48,6 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do @@ -52,7 +48,6 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do
52 &dictionary.DictCode, 48 &dictionary.DictCode,
53 &dictionary.DictName, 49 &dictionary.DictName,
54 &dictionary.Desc, 50 &dictionary.Desc,
55 - &dictionary.IsShow,  
56 pg.Array(&dictionary.DictItems), 51 pg.Array(&dictionary.DictItems),
57 ), 52 ),
58 fmt.Sprintf("INSERT INTO dictionarys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), 53 fmt.Sprintf("INSERT INTO dictionarys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
@@ -60,7 +55,6 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do @@ -60,7 +55,6 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do
60 dictionary.DictCode, 55 dictionary.DictCode,
61 dictionary.DictName, 56 dictionary.DictName,
62 dictionary.Desc, 57 dictionary.Desc,
63 - dictionary.IsShow,  
64 pg.Array(dictionary.DictItems), 58 pg.Array(dictionary.DictItems),
65 ); err != nil { 59 ); err != nil {
66 return dictionary, err 60 return dictionary, err
@@ -72,7 +66,6 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do @@ -72,7 +66,6 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do
72 &dictionary.DictCode, 66 &dictionary.DictCode,
73 &dictionary.DictName, 67 &dictionary.DictName,
74 &dictionary.Desc, 68 &dictionary.Desc,
75 - &dictionary.IsShow,  
76 pg.Array(&dictionary.DictItems), 69 pg.Array(&dictionary.DictItems),
77 ), 70 ),
78 fmt.Sprintf("UPDATE dictionarys SET %s WHERE dictionary_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 71 fmt.Sprintf("UPDATE dictionarys SET %s WHERE dictionary_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
@@ -80,7 +73,6 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do @@ -80,7 +73,6 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do
80 dictionary.DictCode, 73 dictionary.DictCode,
81 dictionary.DictName, 74 dictionary.DictName,
82 dictionary.Desc, 75 dictionary.Desc,
83 - dictionary.IsShow,  
84 pg.Array(dictionary.DictItems), 76 pg.Array(dictionary.DictItems),
85 dictionary.Identify(), 77 dictionary.Identify(),
86 ); err != nil { 78 ); err != nil {
@@ -89,6 +81,7 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do @@ -89,6 +81,7 @@ func (repository *DictionaryRepository) Save(dictionary *domain.Dictionary) (*do
89 } 81 }
90 return dictionary, nil 82 return dictionary, nil
91 } 83 }
  84 +
92 func (repository *DictionaryRepository) Remove(dictionary *domain.Dictionary) (*domain.Dictionary, error) { 85 func (repository *DictionaryRepository) Remove(dictionary *domain.Dictionary) (*domain.Dictionary, error) {
93 tx := repository.transactionContext.PgTx 86 tx := repository.transactionContext.PgTx
94 dictionaryModel := new(models.Dictionary) 87 dictionaryModel := new(models.Dictionary)
@@ -98,11 +91,13 @@ func (repository *DictionaryRepository) Remove(dictionary *domain.Dictionary) (* @@ -98,11 +91,13 @@ func (repository *DictionaryRepository) Remove(dictionary *domain.Dictionary) (*
98 } 91 }
99 return dictionary, nil 92 return dictionary, nil
100 } 93 }
  94 +
101 func (repository *DictionaryRepository) FindOne(queryOptions map[string]interface{}) (*domain.Dictionary, error) { 95 func (repository *DictionaryRepository) FindOne(queryOptions map[string]interface{}) (*domain.Dictionary, error) {
102 tx := repository.transactionContext.PgTx 96 tx := repository.transactionContext.PgTx
103 dictionaryModel := new(models.Dictionary) 97 dictionaryModel := new(models.Dictionary)
104 query := sqlbuilder.BuildQuery(tx.Model(dictionaryModel), queryOptions) 98 query := sqlbuilder.BuildQuery(tx.Model(dictionaryModel), queryOptions)
105 query.SetWhereByQueryOption("dictionary.dictionary_id = ?", "dictionaryId") 99 query.SetWhereByQueryOption("dictionary.dictionary_id = ?", "dictionaryId")
  100 + query.SetWhereByQueryOption("dictionary.dict_code=?", "dictCode")
106 if err := query.First(); err != nil { 101 if err := query.First(); err != nil {
107 if err.Error() == "pg: no rows in result set" { 102 if err.Error() == "pg: no rows in result set" {
108 return nil, fmt.Errorf("没有此资源") 103 return nil, fmt.Errorf("没有此资源")
@@ -116,6 +111,7 @@ func (repository *DictionaryRepository) FindOne(queryOptions map[string]interfac @@ -116,6 +111,7 @@ func (repository *DictionaryRepository) FindOne(queryOptions map[string]interfac
116 return transform.TransformToDictionaryDomainModelFromPgModels(dictionaryModel) 111 return transform.TransformToDictionaryDomainModelFromPgModels(dictionaryModel)
117 } 112 }
118 } 113 }
  114 +
119 func (repository *DictionaryRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Dictionary, error) { 115 func (repository *DictionaryRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Dictionary, error) {
120 tx := repository.transactionContext.PgTx 116 tx := repository.transactionContext.PgTx
121 var dictionaryModels []*models.Dictionary 117 var dictionaryModels []*models.Dictionary
@@ -136,6 +132,7 @@ func (repository *DictionaryRepository) Find(queryOptions map[string]interface{} @@ -136,6 +132,7 @@ func (repository *DictionaryRepository) Find(queryOptions map[string]interface{}
136 return int64(count), dictionarys, nil 132 return int64(count), dictionarys, nil
137 } 133 }
138 } 134 }
  135 +
139 func NewDictionaryRepository(transactionContext *pgTransaction.TransactionContext) (*DictionaryRepository, error) { 136 func NewDictionaryRepository(transactionContext *pgTransaction.TransactionContext) (*DictionaryRepository, error) {
140 if transactionContext == nil { 137 if transactionContext == nil {
141 return nil, fmt.Errorf("transactionContext参数不能为nil") 138 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -4,8 +4,10 @@ import ( @@ -4,8 +4,10 @@ import (
4 "os" 4 "os"
5 "strconv" 5 "strconv"
6 6
  7 + "github.com/beego/beego/v2/core/validation"
7 "github.com/beego/beego/v2/server/web" 8 "github.com/beego/beego/v2/server/web"
8 "github.com/linmadan/egglib-go/web/beego/filters" 9 "github.com/linmadan/egglib-go/web/beego/filters"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/constant"
9 11
10 //_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/port/beego/routers" 12 //_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/port/beego/routers"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/log" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/log"
@@ -27,6 +29,7 @@ func init() { @@ -27,6 +29,7 @@ func init() {
27 web.BConfig.Listen.HTTPPort = port 29 web.BConfig.Listen.HTTPPort = port
28 } 30 }
29 } 31 }
  32 + validation.MessageTmpls = constant.ValidationMessageTmpls
30 web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) 33 web.InsertFilter("/*", web.BeforeExec, filters.AllowCors())
31 web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(log.Logger)) 34 web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(log.Logger))
32 web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(log.Logger), web.WithReturnOnOutput(false)) 35 web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(log.Logger), web.WithReturnOnOutput(false))