作者 tangxuhui

更新

... ... @@ -13,7 +13,6 @@ type GetDictionaryQuery struct {
}
func (getDictionaryQuery *GetDictionaryQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getDictionaryQuery *GetDictionaryQuery) ValidateQuery() error {
... ...
... ... @@ -8,13 +8,12 @@ import (
type ListDictionaryQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
Pageindex int `json:"pageIndex"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
PageSize int `json:"pageSize" valid:"Required"`
}
func (listDictionaryQuery *ListDictionaryQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDictionaryQuery *ListDictionaryQuery) ValidateQuery() error {
... ...
... ... @@ -5,7 +5,6 @@ import (
"sort"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory"
... ... @@ -135,7 +134,12 @@ func (dictionaryService *DictionaryService) ListDictionary(listDictionaryQuery *
} else {
dictionaryRepository = value
}
if count, dictionarys, err := dictionaryRepository.Find(tool_funs.SimpleStructToMap(listDictionaryQuery)); err != nil {
offset := listDictionaryQuery.PageSize * (listDictionaryQuery.Pageindex - 1)
queryCondition := map[string]interface{}{
"limit": listDictionaryQuery.PageSize,
"offset": offset,
}
if count, dictionarys, err := dictionaryRepository.Find(queryCondition); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
... ...
... ... @@ -2,11 +2,11 @@ package constant
import "os"
var POSTGRESQL_DB_NAME = "project"
var POSTGRESQL_DB_NAME = "allied-creation-basic"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = ""
var POSTGRESQL_PASSWORD = "123456"
var POSTGRESQL_HOST = "127.0.0.1"
var POSTGRESQL_PORT = "32432"
var POSTGRESQL_PORT = "5432"
var DISABLE_CREATE_TABLE = false
var DISABLE_SQL_GENERATE_PRINT = false
... ...
... ... @@ -6,9 +6,10 @@ import (
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/log"
//_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
"github.com/linmadan/egglib-go/persistent/pg/hooks"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
)
var DB *pg.DB
... ... @@ -21,10 +22,13 @@ func init() {
Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT),
})
if !constant.DISABLE_SQL_GENERATE_PRINT {
DB.AddQueryHook(hooks.SqlGeneratePrintHook{})
DB.AddQueryHook(hooks.SqlGeneratePrintHook{Logger: log.Logger})
}
if !constant.DISABLE_CREATE_TABLE {
for _, model := range []interface{}{} {
tables := []interface{}{
&models.Dictionary{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
Temp: false,
IfNotExists: true,
... ...
... ... @@ -5,7 +5,7 @@ import (
)
type Dictionary struct {
tableName string `pg:"dictionarys,alias:dictionary"`
tableName string `pg:"dictionary"`
// 字典编号 主键
DictionaryId int64 `pg:",pk"`
// 字典编码
... ... @@ -17,5 +17,5 @@ type Dictionary struct {
// 是否可见【1:不可以】【2:可以】
IsShow int
// 字典值列表
DictItems []domain.DictionaryItem `pg:",array"`
DictItems []domain.DictionaryItem `pg:"type:jsonb"`
}
... ...
... ... @@ -14,7 +14,7 @@ type DictionaryController struct {
func (controller *DictionaryController) CreateDictionary() {
dictionaryService := service.NewDictionaryService(nil)
createDictionaryCommand := &command.CreateDictionaryCommand{}
controller.Unmarshal(createDictionaryCommand)
_ = controller.Unmarshal(createDictionaryCommand)
data, err := dictionaryService.CreateDictionary(createDictionaryCommand)
controller.Response(data, err)
}
... ... @@ -22,7 +22,7 @@ func (controller *DictionaryController) CreateDictionary() {
func (controller *DictionaryController) UpdateDictionary() {
dictionaryService := service.NewDictionaryService(nil)
updateDictionaryCommand := &command.UpdateDictionaryCommand{}
controller.Unmarshal(updateDictionaryCommand)
_ = controller.Unmarshal(updateDictionaryCommand)
dictionaryId, _ := controller.GetInt64(":dictionaryId")
updateDictionaryCommand.DictionaryId = dictionaryId
data, err := dictionaryService.UpdateDictionary(updateDictionaryCommand)
... ... @@ -41,10 +41,7 @@ func (controller *DictionaryController) GetDictionary() {
func (controller *DictionaryController) ListDictionary() {
dictionaryService := service.NewDictionaryService(nil)
listDictionaryQuery := &query.ListDictionaryQuery{}
offset, _ := controller.GetInt("offset")
listDictionaryQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listDictionaryQuery.Limit = limit
_ = controller.Unmarshal(listDictionaryQuery)
data, err := dictionaryService.ListDictionary(listDictionaryQuery)
controller.Response(data, err)
}
... ...