作者 tangxuhui

项目初始

/go.sum
/*.exe
... ...
不能预览此文件类型
... ... @@ -2,6 +2,7 @@ package main
import (
"github.com/beego/beego/v2/server/web"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/port/beego/routers"
)
func main() {
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)
type CreateDictionaryCommand struct {
... ... @@ -18,7 +19,7 @@ type CreateDictionaryCommand struct {
// 是否可见【1:不可以】【2:可以】
IsShow int `json:"isShow,omitempty"`
// 字典值列表
DictItems []*DictionaryItem `json:"dictItems,omitempty"`
DictItems []*domain.DictionaryItem `json:"dictItems,omitempty"`
}
func (createDictionaryCommand *CreateDictionaryCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -4,11 +4,12 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)
type UpdateDictionaryCommand struct {
// 字典编号 主键
DictionaryId int `json:"dictionaryId,omitempty"`
DictionaryId int64 `json:"dictionaryId,omitempty"`
// 字典编码
DictCode string `json:"dictCode,omitempty"`
// 字典名称
... ... @@ -18,7 +19,7 @@ type UpdateDictionaryCommand struct {
// 是否可见【1:不可以】【2:可以】
IsShow int `json:"isShow,omitempty"`
// 字典值列表
DictItems []*DictionaryItem `json:"dictItems,omitempty"`
DictItems []*domain.DictionaryItem `json:"dictItems,omitempty"`
}
func (updateDictionaryCommand *UpdateDictionaryCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -8,7 +8,8 @@ import (
type GetDictionaryQuery struct {
// 字典编码
DictCode string `json:"dictCode,omitempty"`
DictionaryId int64 `json:"dictionaryId"`
DictCode string `json:"dictCode,omitempty"`
}
func (getDictionaryQuery *GetDictionaryQuery) Valid(validation *validation.Validation) {
... ...
package service
import (
"fmt"
"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"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)
// 数据字典设置
... ... @@ -27,10 +30,8 @@ func (dictionaryService *DictionaryService) CreateDictionary(createDictionaryCom
defer func() {
transactionContext.RollbackTransaction()
}()
newDictionary := &dictionary.Dictionary{
Dictionary: createDictionaryCommand.Dictionary,
}
var dictionaryRepository dictionary.DictionaryRepository
newDictionary := &domain.Dictionary{} //TODO
var dictionaryRepository domain.DictionaryRepository
if value, err := factory.CreateDictionaryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -63,7 +64,7 @@ func (dictionaryService *DictionaryService) GetDictionary(getDictionaryQuery *qu
defer func() {
transactionContext.RollbackTransaction()
}()
var dictionaryRepository dictionary.DictionaryRepository
var dictionaryRepository domain.DictionaryRepository
if value, err := factory.CreateDictionaryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -71,12 +72,12 @@ func (dictionaryService *DictionaryService) GetDictionary(getDictionaryQuery *qu
} else {
dictionaryRepository = value
}
dictionary, err := dictionaryRepository.FindOne(map[string]interface{}{"dictionaryId": getDictionaryQuery.DictionaryId})
dictionary, err := dictionaryRepository.FindOne(map[string]interface{}{"dictionaryId": getDictionaryQuery.DictCode})
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("%s", string(getDictionaryQuery.DictionaryId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getDictionaryQuery.DictCode)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -100,7 +101,7 @@ func (dictionaryService *DictionaryService) ListDictionary(listDictionaryQuery *
defer func() {
transactionContext.RollbackTransaction()
}()
var dictionaryRepository dictionary.DictionaryRepository
var dictionaryRepository domain.DictionaryRepository
if value, err := factory.CreateDictionaryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -136,7 +137,7 @@ func (dictionaryService *DictionaryService) RemoveDictionary(removeDictionaryCom
defer func() {
transactionContext.RollbackTransaction()
}()
var dictionaryRepository dictionary.DictionaryRepository
var dictionaryRepository domain.DictionaryRepository
if value, err := factory.CreateDictionaryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -176,7 +177,7 @@ func (dictionaryService *DictionaryService) UpdateDictionary(updateDictionaryCom
defer func() {
transactionContext.RollbackTransaction()
}()
var dictionaryRepository dictionary.DictionaryRepository
var dictionaryRepository domain.DictionaryRepository
if value, err := factory.CreateDictionaryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ...
... ... @@ -3,7 +3,7 @@ package domain
// 字典
type Dictionary struct {
// 字典编号 主键
DictionaryId int `json:"dictionaryId"`
DictionaryId int64 `json:"dictionaryId"`
// 字典编码
DictCode string `json:"dictCode"`
// 字典名称
... ... @@ -32,7 +32,7 @@ func (dictionary *Dictionary) Identify() interface{} {
func (dictionary *Dictionary) Update(data map[string]interface{}) error {
if dictionaryId, ok := data["dictionaryId"]; ok {
dictionary.DictionaryId = dictionaryId.(int)
dictionary.DictionaryId = dictionaryId.(int64)
}
if dictCode, ok := data["dictCode"]; ok {
dictionary.DictCode = dictCode.(string)
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)
type Dictionary struct {
tableName string `pg:"dictionarys,alias:dictionary"`
// 字典编号 主键
DictionaryId int
DictionaryId int64 `pg:",pk"`
// 字典编码
DictCode string
// 字典名称
... ... @@ -13,5 +17,5 @@ type Dictionary struct {
// 是否可见【1:不可以】【2:可以】
IsShow int
// 字典值列表
DictItems []*DictionaryItem `pg:",array"`
DictItems []*domain.DictionaryItem `pg:",array"`
}
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
... ...
package beego
import (
"os"
"strconv"
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
//_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/port/beego/routers"
. "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/log"
)
func init() {
... ... @@ -25,6 +28,6 @@ func init() {
}
}
web.InsertFilter("/*", web.BeforeExec, filters.AllowCors())
web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger))
web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false))
web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(log.Logger))
web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(log.Logger), web.WithReturnOnOutput(false))
}
... ...
... ... @@ -23,7 +23,7 @@ func (controller *DictionaryController) UpdateDictionary() {
dictionaryService := service.NewDictionaryService(nil)
updateDictionaryCommand := &command.UpdateDictionaryCommand{}
controller.Unmarshal(updateDictionaryCommand)
dictionaryId, _ := controller.GetString(":dictionaryId")
dictionaryId, _ := controller.GetInt64(":dictionaryId")
updateDictionaryCommand.DictionaryId = dictionaryId
data, err := dictionaryService.UpdateDictionary(updateDictionaryCommand)
controller.Response(data, err)
... ... @@ -32,7 +32,7 @@ func (controller *DictionaryController) UpdateDictionary() {
func (controller *DictionaryController) GetDictionary() {
dictionaryService := service.NewDictionaryService(nil)
getDictionaryQuery := &query.GetDictionaryQuery{}
dictionaryId, _ := controller.GetString(":dictionaryId")
dictionaryId, _ := controller.GetInt64(":dictionaryId")
getDictionaryQuery.DictionaryId = dictionaryId
data, err := dictionaryService.GetDictionary(getDictionaryQuery)
controller.Response(data, err)
... ...