正在显示
7 个修改的文件
包含
23 行增加
和
20 行删除
| @@ -13,7 +13,6 @@ type GetDictionaryQuery struct { | @@ -13,7 +13,6 @@ type GetDictionaryQuery struct { | ||
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | func (getDictionaryQuery *GetDictionaryQuery) Valid(validation *validation.Validation) { | 15 | func (getDictionaryQuery *GetDictionaryQuery) Valid(validation *validation.Validation) { |
| 16 | - validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 17 | } | 16 | } |
| 18 | 17 | ||
| 19 | func (getDictionaryQuery *GetDictionaryQuery) ValidateQuery() error { | 18 | func (getDictionaryQuery *GetDictionaryQuery) ValidateQuery() error { |
| @@ -8,13 +8,12 @@ import ( | @@ -8,13 +8,12 @@ import ( | ||
| 8 | 8 | ||
| 9 | type ListDictionaryQuery struct { | 9 | type ListDictionaryQuery struct { |
| 10 | // 查询偏离量 | 10 | // 查询偏离量 |
| 11 | - Offset int `json:"offset" valid:"Required"` | 11 | + Pageindex int `json:"pageIndex"` |
| 12 | // 查询限制 | 12 | // 查询限制 |
| 13 | - Limit int `json:"limit" valid:"Required"` | 13 | + PageSize int `json:"pageSize" valid:"Required"` |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | func (listDictionaryQuery *ListDictionaryQuery) Valid(validation *validation.Validation) { | 16 | func (listDictionaryQuery *ListDictionaryQuery) Valid(validation *validation.Validation) { |
| 17 | - validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | } | 17 | } |
| 19 | 18 | ||
| 20 | func (listDictionaryQuery *ListDictionaryQuery) ValidateQuery() error { | 19 | func (listDictionaryQuery *ListDictionaryQuery) ValidateQuery() error { |
| @@ -5,7 +5,6 @@ import ( | @@ -5,7 +5,6 @@ import ( | ||
| 5 | "sort" | 5 | "sort" |
| 6 | 6 | ||
| 7 | "github.com/linmadan/egglib-go/core/application" | 7 | "github.com/linmadan/egglib-go/core/application" |
| 8 | - "github.com/linmadan/egglib-go/utils/tool_funs" | ||
| 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/command" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/query" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/query" |
| 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory" |
| @@ -135,7 +134,12 @@ func (dictionaryService *DictionaryService) ListDictionary(listDictionaryQuery * | @@ -135,7 +134,12 @@ func (dictionaryService *DictionaryService) ListDictionary(listDictionaryQuery * | ||
| 135 | } else { | 134 | } else { |
| 136 | dictionaryRepository = value | 135 | dictionaryRepository = value |
| 137 | } | 136 | } |
| 138 | - if count, dictionarys, err := dictionaryRepository.Find(tool_funs.SimpleStructToMap(listDictionaryQuery)); err != nil { | 137 | + offset := listDictionaryQuery.PageSize * (listDictionaryQuery.Pageindex - 1) |
| 138 | + queryCondition := map[string]interface{}{ | ||
| 139 | + "limit": listDictionaryQuery.PageSize, | ||
| 140 | + "offset": offset, | ||
| 141 | + } | ||
| 142 | + if count, dictionarys, err := dictionaryRepository.Find(queryCondition); err != nil { | ||
| 139 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 143 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 140 | } else { | 144 | } else { |
| 141 | if err := transactionContext.CommitTransaction(); err != nil { | 145 | if err := transactionContext.CommitTransaction(); err != nil { |
| @@ -2,11 +2,11 @@ package constant | @@ -2,11 +2,11 @@ package constant | ||
| 2 | 2 | ||
| 3 | import "os" | 3 | import "os" |
| 4 | 4 | ||
| 5 | -var POSTGRESQL_DB_NAME = "project" | 5 | +var POSTGRESQL_DB_NAME = "allied-creation-basic" |
| 6 | var POSTGRESQL_USER = "postgres" | 6 | var POSTGRESQL_USER = "postgres" |
| 7 | -var POSTGRESQL_PASSWORD = "" | 7 | +var POSTGRESQL_PASSWORD = "123456" |
| 8 | var POSTGRESQL_HOST = "127.0.0.1" | 8 | var POSTGRESQL_HOST = "127.0.0.1" |
| 9 | -var POSTGRESQL_PORT = "32432" | 9 | +var POSTGRESQL_PORT = "5432" |
| 10 | var DISABLE_CREATE_TABLE = false | 10 | var DISABLE_CREATE_TABLE = false |
| 11 | var DISABLE_SQL_GENERATE_PRINT = false | 11 | var DISABLE_SQL_GENERATE_PRINT = false |
| 12 | 12 |
| @@ -6,9 +6,10 @@ import ( | @@ -6,9 +6,10 @@ import ( | ||
| 6 | "github.com/go-pg/pg/v10" | 6 | "github.com/go-pg/pg/v10" |
| 7 | "github.com/go-pg/pg/v10/orm" | 7 | "github.com/go-pg/pg/v10/orm" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/constant" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/constant" |
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/log" | ||
| 9 | 10 | ||
| 10 | - //_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models" | ||
| 11 | "github.com/linmadan/egglib-go/persistent/pg/hooks" | 11 | "github.com/linmadan/egglib-go/persistent/pg/hooks" |
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models" | ||
| 12 | ) | 13 | ) |
| 13 | 14 | ||
| 14 | var DB *pg.DB | 15 | var DB *pg.DB |
| @@ -21,10 +22,13 @@ func init() { | @@ -21,10 +22,13 @@ func init() { | ||
| 21 | Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT), | 22 | Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT), |
| 22 | }) | 23 | }) |
| 23 | if !constant.DISABLE_SQL_GENERATE_PRINT { | 24 | if !constant.DISABLE_SQL_GENERATE_PRINT { |
| 24 | - DB.AddQueryHook(hooks.SqlGeneratePrintHook{}) | 25 | + DB.AddQueryHook(hooks.SqlGeneratePrintHook{Logger: log.Logger}) |
| 25 | } | 26 | } |
| 26 | if !constant.DISABLE_CREATE_TABLE { | 27 | if !constant.DISABLE_CREATE_TABLE { |
| 27 | - for _, model := range []interface{}{} { | 28 | + tables := []interface{}{ |
| 29 | + &models.Dictionary{}, | ||
| 30 | + } | ||
| 31 | + for _, model := range tables { | ||
| 28 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | 32 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ |
| 29 | Temp: false, | 33 | Temp: false, |
| 30 | IfNotExists: true, | 34 | IfNotExists: true, |
| @@ -5,7 +5,7 @@ import ( | @@ -5,7 +5,7 @@ import ( | ||
| 5 | ) | 5 | ) |
| 6 | 6 | ||
| 7 | type Dictionary struct { | 7 | type Dictionary struct { |
| 8 | - tableName string `pg:"dictionarys,alias:dictionary"` | 8 | + tableName string `pg:"dictionary"` |
| 9 | // 字典编号 主键 | 9 | // 字典编号 主键 |
| 10 | DictionaryId int64 `pg:",pk"` | 10 | DictionaryId int64 `pg:",pk"` |
| 11 | // 字典编码 | 11 | // 字典编码 |
| @@ -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:"type:jsonb"` |
| 21 | } | 21 | } |
| @@ -14,7 +14,7 @@ type DictionaryController struct { | @@ -14,7 +14,7 @@ type DictionaryController struct { | ||
| 14 | func (controller *DictionaryController) CreateDictionary() { | 14 | func (controller *DictionaryController) CreateDictionary() { |
| 15 | dictionaryService := service.NewDictionaryService(nil) | 15 | dictionaryService := service.NewDictionaryService(nil) |
| 16 | createDictionaryCommand := &command.CreateDictionaryCommand{} | 16 | createDictionaryCommand := &command.CreateDictionaryCommand{} |
| 17 | - controller.Unmarshal(createDictionaryCommand) | 17 | + _ = controller.Unmarshal(createDictionaryCommand) |
| 18 | data, err := dictionaryService.CreateDictionary(createDictionaryCommand) | 18 | data, err := dictionaryService.CreateDictionary(createDictionaryCommand) |
| 19 | controller.Response(data, err) | 19 | controller.Response(data, err) |
| 20 | } | 20 | } |
| @@ -22,7 +22,7 @@ func (controller *DictionaryController) CreateDictionary() { | @@ -22,7 +22,7 @@ func (controller *DictionaryController) CreateDictionary() { | ||
| 22 | func (controller *DictionaryController) UpdateDictionary() { | 22 | func (controller *DictionaryController) UpdateDictionary() { |
| 23 | dictionaryService := service.NewDictionaryService(nil) | 23 | dictionaryService := service.NewDictionaryService(nil) |
| 24 | updateDictionaryCommand := &command.UpdateDictionaryCommand{} | 24 | updateDictionaryCommand := &command.UpdateDictionaryCommand{} |
| 25 | - controller.Unmarshal(updateDictionaryCommand) | 25 | + _ = controller.Unmarshal(updateDictionaryCommand) |
| 26 | dictionaryId, _ := controller.GetInt64(":dictionaryId") | 26 | dictionaryId, _ := controller.GetInt64(":dictionaryId") |
| 27 | updateDictionaryCommand.DictionaryId = dictionaryId | 27 | updateDictionaryCommand.DictionaryId = dictionaryId |
| 28 | data, err := dictionaryService.UpdateDictionary(updateDictionaryCommand) | 28 | data, err := dictionaryService.UpdateDictionary(updateDictionaryCommand) |
| @@ -41,10 +41,7 @@ func (controller *DictionaryController) GetDictionary() { | @@ -41,10 +41,7 @@ func (controller *DictionaryController) GetDictionary() { | ||
| 41 | func (controller *DictionaryController) ListDictionary() { | 41 | func (controller *DictionaryController) ListDictionary() { |
| 42 | dictionaryService := service.NewDictionaryService(nil) | 42 | dictionaryService := service.NewDictionaryService(nil) |
| 43 | listDictionaryQuery := &query.ListDictionaryQuery{} | 43 | listDictionaryQuery := &query.ListDictionaryQuery{} |
| 44 | - offset, _ := controller.GetInt("offset") | ||
| 45 | - listDictionaryQuery.Offset = offset | ||
| 46 | - limit, _ := controller.GetInt("limit") | ||
| 47 | - listDictionaryQuery.Limit = limit | 44 | + _ = controller.Unmarshal(listDictionaryQuery) |
| 48 | data, err := dictionaryService.ListDictionary(listDictionaryQuery) | 45 | data, err := dictionaryService.ListDictionary(listDictionaryQuery) |
| 49 | controller.Response(data, err) | 46 | controller.Response(data, err) |
| 50 | } | 47 | } |
-
请 注册 或 登录 后发表评论