作者 tangxuhui

构建baseController

... ... @@ -2,8 +2,8 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/custommenu/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/custommenu/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/custommenu/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/custommenu/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
... ...
... ... @@ -4,9 +4,12 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type RoleUserInfoQuery struct {
// 操作人
Operator domain.Operator `json:"-"`
// 角色ID
RoleId int64 `json:"roleId" valid:"Required"`
}
... ...
package web_client
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type baseController struct {
beego.BaseController
}
func (controller *baseController) returnPageListData(count int64, data interface{}, err error, pageNumber int) {
dataMap := map[string]interface{}{
"totalRow": count,
"pageNumber": pageNumber,
"list": data,
}
controller.Response(dataMap, err)
}
func (controller *baseController) GetUserId() int64 {
return 1
}
func (controller *baseController) GetCompanyId() int64 {
return 1
}
func (controller *baseController) GetUserBaseId() int64 {
return 1
}
func (controller *baseController) GetOrgId() int64 {
return 1
}
func (controller *baseController) GetOperator() domain.Operator {
return domain.Operator{
UserId: 1,
CompanyId: 1,
OrgId: 1,
UserBaseId: 1,
}
}
... ...
package web_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/custommenu/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/custommenu/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/custommenu/service"
)
type MenuController struct {
baseController
}
func (controller *MenuController) MenuList() {
menuService := service.NewMenuService(nil)
menuListQuery := &query.MenuListQuery{}
menuListQuery.Operator = controller.GetOperator()
data, err := menuService.MenuList(menuListQuery)
controller.Response(data, err)
}
func (controller *MenuController) MenuUpdate() {
menuService := service.NewMenuService(nil)
menuUpdateQuery := &command.MenuUpdateCommand{}
controller.Unmarshal(menuUpdateQuery)
menuUpdateQuery.Operator = controller.GetOperator()
data, err := menuService.MenuUpdate(menuUpdateQuery)
controller.Response(data, err)
}
func (controller *MenuController) MenuFavorite() {
menuService := service.NewMenuService(nil)
menuFavoriteCommand := &command.MenuFavoriteCommand{}
controller.Unmarshal(menuFavoriteCommand)
data, err := menuService.MenuFavorite(menuFavoriteCommand)
controller.Response(data, err)
}
... ...
package web_client
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/orgs/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/orgs/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/orgs/service"
)
type OrgsController struct {
beego.BaseController
baseController
}
func (controller *OrgsController) OrgAdd() {
orgsService := service.NewOrgsService(nil)
orgAddCommand := &command.OrgAddCommand{}
controller.Unmarshal(orgAddCommand)
orgAddCommand.Operator = controller.GetOperator()
data, err := orgsService.OrgAdd(orgAddCommand)
controller.Response(data, err)
}
... ... @@ -25,6 +25,7 @@ func (controller *OrgsController) OrgUpdate() {
controller.Unmarshal(orgUpdateCommand)
orgId := controller.GetString(":orgId")
orgUpdateCommand.OrgId = orgId
orgUpdateCommand.Operator = controller.GetOperator()
data, err := orgsService.OrgUpdate(orgUpdateCommand)
controller.Response(data, err)
}
... ... @@ -32,6 +33,8 @@ func (controller *OrgsController) OrgUpdate() {
func (controller *OrgsController) OrgList() {
orgsService := service.NewOrgsService(nil)
orgListQuery := &query.OrgListQuery{}
controller.Unmarshal(orgListQuery)
orgListQuery.Operator = controller.GetOperator()
data, err := orgsService.OrgList(orgListQuery)
controller.Response(data, err)
}
... ... @@ -41,6 +44,7 @@ func (controller *OrgsController) OrgGet() {
orgGetQuery := &query.OrgGetQuery{}
orgId := controller.GetString(":orgId")
orgGetQuery.OrgId = orgId
orgGetQuery.Operator = controller.GetOperator()
data, err := orgsService.OrgGet(orgGetQuery)
controller.Response(data, err)
}
... ...
package web_client
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/roles/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/roles/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/roles/service"
)
type RolesController struct {
beego.BaseController
baseController
}
func (controller *RolesController) returnPageListData(count int64, data interface{}, err error, pageNumber int) {
dataMap := map[string]interface{}{
"totalRow": count,
"pageNumber": pageNumber,
"list": data,
}
controller.Response(dataMap, err)
}
func (controller *RolesController) RoleAdd() {
rolesService := service.NewRolesService(nil)
roleAddCommand := &command.RoleAddCommand{}
controller.Unmarshal(roleAddCommand)
roleAddCommand.Operator = controller.GetOperator()
data, err := rolesService.RoleAdd(roleAddCommand)
controller.Response(data, err)
}
... ... @@ -33,6 +25,7 @@ func (controller *RolesController) RoleUpdate() {
controller.Unmarshal(roleUpdateCommand)
roleId := controller.GetString(":roleId")
roleUpdateCommand.RoleId = roleId
roleUpdateCommand.Operator = controller.GetOperator()
data, err := rolesService.RoleEdit(roleUpdateCommand)
controller.Response(data, err)
}
... ... @@ -41,6 +34,7 @@ func (controller *RolesController) RoleList() {
rolesService := service.NewRolesService(nil)
roleListQuery := &query.RoleListQuery{}
controller.Unmarshal(roleListQuery)
roleListQuery.Operator = controller.GetOperator()
cnt, data, err := rolesService.RoleList(roleListQuery)
controller.returnPageListData(cnt, data, err, roleListQuery.PageNumber)
}
... ... @@ -50,6 +44,7 @@ func (controller *RolesController) RoleGet() {
roleGetQuery := &query.RoleGetQuery{}
roleId := controller.GetString(":roleId")
roleGetQuery.RoleId = roleId
roleGetQuery.Operator = controller.GetOperator()
data, err := rolesService.RoleGet(roleGetQuery)
controller.Response(data, err)
}
... ... @@ -59,6 +54,7 @@ func (controller *RolesController) RoleUserInfo() {
roleUserInfoQuery := &query.RoleUserInfoQuery{}
roleId, _ := controller.GetInt64(":roleId")
roleUserInfoQuery.RoleId = roleId
roleUserInfoQuery.Operator = controller.GetOperator()
data, err := rolesService.RoleUserInfo(roleUserInfoQuery)
controller.Response(data, err)
}
... ... @@ -67,6 +63,7 @@ func (controller *RolesController) RoleUserAdd() {
rolesService := service.NewRolesService(nil)
roleUserAddQuery := &command.RoleUserAddCommand{}
controller.Unmarshal(roleUserAddQuery)
roleUserAddQuery.Operator = controller.GetOperator()
data, err := rolesService.RoleUserAdd(roleUserAddQuery)
controller.Response(data, err)
}
... ... @@ -75,6 +72,7 @@ func (controller *RolesController) RoleUserDelete() {
rolesService := service.NewRolesService(nil)
roleUserDeleteQuery := &command.RoleUserDeleteCommand{}
controller.Unmarshal(roleUserDeleteQuery)
roleUserDeleteQuery.Operator = controller.GetOperator()
data, err := rolesService.RoleUserDelete(roleUserDeleteQuery)
controller.Response(data, err)
}
... ... @@ -99,6 +97,7 @@ func (controller *RolesController) RoleMenuEdit() {
controller.Unmarshal(roleMenuEditQuery)
roleId := controller.GetString(":roleId")
roleMenuEditQuery.RoleId = roleId
roleMenuEditQuery.Operator = controller.GetOperator()
data, err := rolesService.RoleMenuEdit(roleMenuEditQuery)
controller.Response(data, err)
}
... ...
package web_client
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/service"
)
type UsersController struct {
beego.BaseController
}
func (controller *UsersController) returnPageListData(count int64, data interface{}, err error, pageNumber int) {
dataMap := map[string]interface{}{
"totalRow": count,
"pageNumber": pageNumber,
"list": data,
}
controller.Response(dataMap, err)
baseController
}
func (controller *UsersController) CompanyUserAdd() {
usersService := service.NewUsersService(nil)
companyUserAddCommand := &command.CompanyUserAddCommand{}
controller.Unmarshal(companyUserAddCommand)
companyUserAddCommand.Operator = controller.GetOperator()
data, err := usersService.CompanyUserAdd(companyUserAddCommand)
controller.Response(data, err)
}
... ... @@ -32,6 +23,7 @@ func (controller *UsersController) CompanyUserUpdate() {
usersService := service.NewUsersService(nil)
companyUserUpdateCommand := &command.CompanyUserUpdateCommand{}
controller.Unmarshal(companyUserUpdateCommand)
companyUserUpdateCommand.Operator = controller.GetOperator()
data, err := usersService.CompanyUserUpdate(companyUserUpdateCommand)
controller.Response(data, err)
}
... ... @@ -40,6 +32,7 @@ func (controller *UsersController) CompanyUserList() {
usersService := service.NewUsersService(nil)
companyUserListQuery := &query.CompanyUserListQuery{}
controller.Unmarshal(companyUserListQuery)
companyUserListQuery.Operator = controller.GetOperator()
cnt, data, err := usersService.CompanyUserList(companyUserListQuery)
controller.returnPageListData(cnt, data, err, companyUserListQuery.PageNumber)
}
... ... @@ -49,6 +42,7 @@ func (controller *UsersController) CompanyUserGet() {
companyUserGetQuery := &query.CompanyUserGetQuery{}
userId := controller.GetString(":userId")
companyUserGetQuery.UsersId = userId
companyUserGetQuery.Operator = controller.GetOperator()
data, err := usersService.CompanyUserGet(companyUserGetQuery)
controller.Response(data, err)
}
... ... @@ -57,6 +51,7 @@ func (controller *UsersController) CompanyUserEnable() {
usersService := service.NewUsersService(nil)
companyUserEnableCommand := &command.CompanyUserEnableCommand{}
controller.Unmarshal(companyUserEnableCommand)
companyUserEnableCommand.Operator = controller.GetOperator()
data, err := usersService.CompanyUserEnable(companyUserEnableCommand)
controller.Response(data, err)
}
... ... @@ -65,6 +60,7 @@ func (controller *UsersController) CompanyUserResetPassword() {
usersService := service.NewUsersService(nil)
companyUserResetPasswordCommand := &command.CompanyUserResetPasswordCommand{}
controller.Unmarshal(companyUserResetPasswordCommand)
companyUserResetPasswordCommand.Operator = controller.GetOperator()
data, err := usersService.CompanyUserResetPassword(companyUserResetPasswordCommand)
controller.Response(data, err)
}
... ... @@ -73,6 +69,7 @@ func (controller *UsersController) CooperationUserAdd() {
usersService := service.NewUsersService(nil)
cooperationUserAddCommand := &command.CooperationUserAddCommand{}
controller.Unmarshal(cooperationUserAddCommand)
cooperationUserAddCommand.Operator = controller.GetOperator()
data, err := usersService.CooperationUserAdd(cooperationUserAddCommand)
controller.Response(data, err)
}
... ... @@ -81,6 +78,7 @@ func (controller *UsersController) CooperationUserUpdate() {
usersService := service.NewUsersService(nil)
cooperationUserUpdateCommand := &command.CooperationUserUpdateCommand{}
controller.Unmarshal(cooperationUserUpdateCommand)
cooperationUserUpdateCommand.Operator = controller.GetOperator()
data, err := usersService.CooperationUserUpdate(cooperationUserUpdateCommand)
controller.Response(data, err)
}
... ... @@ -89,6 +87,7 @@ func (controller *UsersController) CooperationUserList() {
usersService := service.NewUsersService(nil)
cooperationUserListQuery := &query.CooperationUserListQuery{}
controller.Unmarshal(cooperationUserListQuery)
cooperationUserListQuery.Operator = controller.GetOperator()
cnt, data, err := usersService.CooperationUserList(cooperationUserListQuery)
controller.returnPageListData(cnt, data, err, cooperationUserListQuery.PageNumber)
}
... ... @@ -98,6 +97,7 @@ func (controller *UsersController) CooperationUserGet() {
cooperationUserGetQuery := &query.CooperationUserGetQuery{}
userId := controller.GetString(":userId")
cooperationUserGetQuery.UsersId = userId
cooperationUserGetQuery.Operator = controller.GetOperator()
data, err := usersService.CooperationUserGet(cooperationUserGetQuery)
controller.Response(data, err)
}
... ... @@ -106,6 +106,7 @@ func (controller *UsersController) CooperationUserEnable() {
usersService := service.NewUsersService(nil)
cooperationUserEnableCommand := &command.CooperationUserEnableCommand{}
controller.Unmarshal(cooperationUserEnableCommand)
cooperationUserEnableCommand.Operator = controller.GetOperator()
data, err := usersService.CooperationUserEnable(cooperationUserEnableCommand)
controller.Response(data, err)
}
... ... @@ -114,6 +115,7 @@ func (controller *UsersController) CooperationUserResetPassword() {
usersService := service.NewUsersService(nil)
cooperationUserResetPasswordCommand := &command.CooperationUserResetPasswordCommand{}
controller.Unmarshal(cooperationUserResetPasswordCommand)
cooperationUserResetPasswordCommand.Operator = controller.GetOperator()
data, err := usersService.CooperationUserResetPassword(cooperationUserResetPasswordCommand)
controller.Response(data, err)
}
... ...
package middleware
... ...