作者 tangxuhui

新增 部门管理 模块

{"D:\\workspaceGo\\src\\allied-creation-gateway\\pkg\\port\\beego":1627356799005386400}
\ No newline at end of file
{"D:\\workspaceGo\\src\\allied-creation-gateway\\pkg\\port\\beego":1627475088561293500}
\ No newline at end of file
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type OrgAddCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 组织编码
OrgCode string `json:"orgCode" valid:"Required"`
// 组织名称
OrgName string `json:"orgName" valid:"Required"`
IsOrg int `json:"isOrg" valid:"Required"`
// 父级id
ParentId string `json:"parentId" valid:"Required"`
}
func (orgAddCommand *OrgAddCommand) Valid(validation *validation.Validation) {
}
func (orgAddCommand *OrgAddCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgAddCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type OrgEnableCommand struct {
//操作人
Operator domain.Operator `json:"-"`
OrgId string `json:"orgId,omitempty"`
Status int `json:"status,omitempty"`
}
func (orgEnableCommand *OrgEnableCommand) Valid(validation *validation.Validation) {
}
func (orgEnableCommand *OrgEnableCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgEnableCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type OrgRemoveCommand struct {
//操作人
Operator domain.Operator `json:"-"`
OrgId []string `json:"orgId,omitempty"`
}
func (orgRemoveCommand *OrgRemoveCommand) Valid(validation *validation.Validation) {
}
func (orgRemoveCommand *OrgRemoveCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgRemoveCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type OrgUpdateCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 组织ID
OrgId string `json:"orgId" valid:"Required"`
// 组织编码
OrgCode string `json:"orgCode" valid:"Required"`
// 组织名称
OrgName string `json:"orgName" valid:"Required"`
IsOrg int `json:"isOrg" valid:"Required"`
// 父级id
ParentId string `json:"parentId" valid:"Required"`
}
func (orgUpdateCommand *OrgUpdateCommand) Valid(validation *validation.Validation) {
}
func (orgUpdateCommand *OrgUpdateCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgUpdateCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package dto
type OrgItem struct {
OrgId string `json:"orgId"`
OrgName string `json:"orgName"`
ParentId string `json:"parentId"`
IsOrg int `json:"isOrg"`
OrgCode string `json:"orgCode"`
ParentDepName string `json:"parentDepName"`
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type OrgGetQuery struct {
//操作人
Operator domain.Operator `json:"-"`
// 组织ID
OrgId string `json:"orgId" valid:"Required"`
}
func (orgGetQuery *OrgGetQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (orgGetQuery *OrgGetQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(orgGetQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type OrgListQuery struct {
//操作人
Operator domain.Operator `json:"-"`
OrgCode string `json:"OrgCode"`
DepName string `json:"depName"`
ParentId int `json:"parentId"`
}
func (orgListQuery *OrgListQuery) Valid(validation *validation.Validation) {
}
func (orgListQuery *OrgListQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(orgListQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"strconv"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/orgs/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/orgs/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/orgs/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
// 组织管理
type OrgsService struct {
}
// 创建组织管理
func (orgsService *OrgsService) OrgAdd(orgAddCommand *command.OrgAddCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgAddCommand.Operator.CompanyId,
orgAddCommand.Operator.OrgId,
orgAddCommand.Operator.UserId)
parentId, _ := strconv.Atoi(orgAddCommand.ParentId)
result, err := creationUserGateway.OrgCreate(allied_creation_user.ReqOrgCreate{
CompanyId: int(orgAddCommand.Operator.CompanyId),
IsOrg: orgAddCommand.IsOrg,
OrgCode: orgAddCommand.OrgCode,
OrgName: orgAddCommand.OrgName,
ParentId: parentId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
data := struct {
OrgId int `json:"orgId"`
command.OrgAddCommand
}{
OrgId: result.OrgId,
OrgAddCommand: *orgAddCommand,
}
return data, nil
}
// 禁用、启用组织管理
func (orgsService *OrgsService) OrgEnable(orgEnableCommand *command.OrgEnableCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgEnableCommand.Operator.CompanyId,
orgEnableCommand.Operator.OrgId,
orgEnableCommand.Operator.UserId)
orgId, _ := strconv.Atoi(orgEnableCommand.OrgId)
_, err := creationUserGateway.OrgEnable(allied_creation_user.ReqOrgEnable{
OrgId: orgId,
OrgStatus: orgEnableCommand.Status,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return orgEnableCommand, nil
}
// 返回组织管理
func (orgsService *OrgsService) OrgGet(orgGetQuery *query.OrgGetQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgGetQuery.Operator.CompanyId,
orgGetQuery.Operator.OrgId,
orgGetQuery.Operator.UserId)
orgId, _ := strconv.Atoi(orgGetQuery.OrgId)
result, err := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{
OrgId: orgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
data := dto.OrgItem{
OrgId: strconv.Itoa(result.Org.OrgID),
OrgName: result.Org.OrgName,
ParentId: strconv.Itoa(result.Org.ParentID),
IsOrg: result.Org.IsOrg,
OrgCode: result.Org.OrgCode,
ParentDepName: result.Org.Ext.ParentDepName,
}
return data, nil
}
// 返回组织管理列表
func (orgsService *OrgsService) OrgList(orgListQuery *query.OrgListQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgListQuery.Operator.CompanyId,
orgListQuery.Operator.OrgId,
orgListQuery.Operator.UserId)
result, err := creationUserGateway.OrgSearch(allied_creation_user.ReqOrgSearch{
CompanyId: int(orgListQuery.Operator.CompanyId),
DepName: orgListQuery.DepName,
IsOrg: 0,
Limit: 0,
Offset: 0,
OrgCode: orgListQuery.OrgCode,
ParentId: orgListQuery.ParentId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var (
dataList []dto.OrgItem
item dto.OrgItem
)
for _, v := range result.Orgs {
item = dto.OrgItem{
OrgId: strconv.Itoa(v.OrgID),
OrgName: v.OrgName,
ParentId: strconv.Itoa(v.ParentID),
IsOrg: v.IsOrg,
OrgCode: v.OrgCode,
ParentDepName: v.Ext.ParentDepName,
}
dataList = append(dataList, item)
}
return dataList, nil
}
// 更新组织管理
func (orgsService *OrgsService) OrgUpdate(orgUpdateCommand *command.OrgUpdateCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgUpdateCommand.Operator.CompanyId,
orgUpdateCommand.Operator.OrgId,
orgUpdateCommand.Operator.UserId)
parentId, _ := strconv.Atoi(orgUpdateCommand.ParentId)
_, err := creationUserGateway.OrgCreate(allied_creation_user.ReqOrgCreate{
IsOrg: orgUpdateCommand.IsOrg,
OrgCode: orgUpdateCommand.OrgCode,
OrgName: orgUpdateCommand.OrgName,
ParentId: parentId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return orgUpdateCommand, nil
}
func NewOrgsService(options map[string]interface{}) *OrgsService {
newOrgsService := &OrgsService{}
return newOrgsService
}
... ...
... ... @@ -20,14 +20,21 @@ func (rolesService *RolesService) RoleAdd(roleAddCommand *command.RoleAddCommand
roleAddCommand.Operator.CompanyId,
roleAddCommand.Operator.OrgId,
roleAddCommand.Operator.UserId)
_, err := creationUserGateway.RoleCreate(allied_creation_user.ReqRoleCreate{
result, err := creationUserGateway.RoleCreate(allied_creation_user.ReqRoleCreate{
RoleName: roleAddCommand.RoleName,
Desc: roleAddCommand.Desc,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return roleAddCommand, err
data := struct {
RoleId string `json:"roleId"`
command.RoleAddCommand
}{
RoleId: strconv.Itoa(int(result.RoleID)),
RoleAddCommand: *roleAddCommand,
}
return data, err
}
// 编辑role
... ... @@ -55,22 +62,6 @@ func (rolesService *RolesService) RoleGet(roleGetQuery *query.RoleGetQuery) (int
roleGetQuery.Operator.OrgId,
roleGetQuery.Operator.UserId)
roleId, _ := strconv.Atoi(roleGetQuery.RoleId)
result, err := creationUserGateway.RoleGet(allied_creation_user.ReqRoleGet{
RoleId: int64(roleId),
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 返角全部详情色
func (rolesService *RolesService) RoleAllDetail(roleGetQuery *query.RoleGetQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
roleGetQuery.Operator.CompanyId,
roleGetQuery.Operator.OrgId,
roleGetQuery.Operator.UserId)
roleId, _ := strconv.Atoi(roleGetQuery.RoleId)
roleData, err := creationUserGateway.RoleGet(allied_creation_user.ReqRoleGet{
RoleId: int64(roleId),
})
... ... @@ -122,7 +113,7 @@ func (rolesService *RolesService) RoleMenuBeforeEdit(roleMenuBeforeEditQuery *qu
// 编辑角色关联用户的前置准备数据
func (rolesService *RolesService) RoleUserBeforeEdit(roleUserBeforeEditQuery *query.RoleUserBeforeEditQuery) (interface{}, error) {
//TODO
return nil, nil
}
... ... @@ -223,7 +214,7 @@ func (rolesService *RolesService) RoleUserDelete(roleUserDeleteCommand *command.
// 角色下关联用户的数据
func (rolesService *RolesService) RoleUserInfo(roleUserInfoQuery *query.RoleUserInfoQuery) (interface{}, error) {
//TODO
return nil, nil
}
... ...
... ... @@ -67,7 +67,7 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.
userRole = append(userRole, int64(id))
}
}
_, err := creationUserGateway.UserCreate(allied_creation_user.ReqCreateUser{
result, err := creationUserGateway.UserCreate(allied_creation_user.ReqCreateUser{
CompanyId: companyUserAddCommand.Operator.CompanyId,
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType: 1,
... ... @@ -84,7 +84,15 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.
Avatar: companyUserAddCommand.Avator,
Email: companyUserAddCommand.Avator,
})
return companyUserAddCommand, err
data := struct {
UserId string `json:"userId"`
command.CompanyUserAddCommand
}{
UserId: strconv.Itoa(result.UserId),
CompanyUserAddCommand: *companyUserAddCommand,
}
return data, err
}
// 启用禁用公司用户信息
... ... @@ -197,7 +205,7 @@ func (usersService *UsersService) CooperationUserAdd(cooperationUserAddCommand *
cooperationUserAddCommand.Operator.CompanyId,
cooperationUserAddCommand.Operator.OrgId,
cooperationUserAddCommand.Operator.UserId)
_, err := creationUserGateway.CooperatorUserCreate(allied_creation_user.ReqCreateCooperatorUser{
result, err := creationUserGateway.CooperatorUserCreate(allied_creation_user.ReqCreateCooperatorUser{
CooperationCompany: cooperationUserAddCommand.CooperationCompany,
CooperationDeadline: time.Unix(cooperationUserAddCommand.CooperationDeadline, 0),
Email: cooperationUserAddCommand.Email,
... ... @@ -209,7 +217,14 @@ func (usersService *UsersService) CooperationUserAdd(cooperationUserAddCommand *
Phone: cooperationUserAddCommand.Phone,
Password: "", //TODO 填充默认密码
})
return cooperationUserAddCommand, err
data := struct {
UserId string `json:"userId"`
command.CooperationUserAddCommand
}{
UserId: strconv.Itoa(result.UserId),
CooperationUserAddCommand: *cooperationUserAddCommand,
}
return data, err
}
// 启用禁用共创用户信息
... ...
... ... @@ -10,7 +10,7 @@ import (
)
// Org 创建组织
func (gateway HttplibAlliedCreationUser) OrgCreate(param ReqOrg) (*DataOrg, error) {
func (gateway HttplibAlliedCreationUser) OrgCreate(param ReqOrgCreate) (*DataOrgCreate, error) {
url := gateway.baseUrL + "/org"
method := "post"
req := gateway.CreateRequest(url, method)
... ... @@ -35,7 +35,7 @@ func (gateway HttplibAlliedCreationUser) OrgCreate(param ReqOrg) (*DataOrg, erro
if err != nil {
return nil, fmt.Errorf("解析创建组织:%w", err)
}
var data DataOrg
var data DataOrgCreate
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ... @@ -166,7 +166,7 @@ func (gateway HttplibAlliedCreationUser) OrgEnable(param ReqOrgEnable) (*DataOrg
// Org[orgId} 返回组织
func (gateway HttplibAlliedCreationUser) OrgGet(param ReqOrgGet) (*DataOrgGet, error) {
url := gateway.baseUrL + "/org/" + strconv.FormatInt(param.OrgId, 10)
url := gateway.baseUrL + "/org/" + strconv.Itoa(param.OrgId)
method := "get"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:返回组织。", map[string]interface{}{
... ...
... ... @@ -2,10 +2,16 @@ package allied_creation_user
//创建组织
type (
ReqOrg struct {
ReqOrgCreate struct {
CompanyId int `json:"companyId"`
IsOrg int `json:"isOrg"`
OrgCode string `json:"orgCode"`
OrgName string `json:"orgName"`
ParentId int `json:"parentId"`
}
DataOrg struct {
DataOrgCreate struct {
OrgId int `json:"orgId"`
}
)
... ... @@ -42,6 +48,8 @@ type (
//设置组织启用状态
type (
ReqOrgEnable struct {
OrgId int `json:"orgId"`
OrgStatus int `json:"orgStatus"` // 组织状态 1:启用 2:禁用 3.删除
}
DataOrgEnable struct {
... ... @@ -51,18 +59,60 @@ type (
//返回组织
type (
ReqOrgGet struct {
OrgId int64
OrgId int `json:"orgId"`
}
DataOrgGet struct {
Org struct {
CompanyID int `json:"companyId"`
Ext struct {
DepName string `json:"depName"`
OrgName string `json:"orgName"`
ParentDepName string `json:"parentDepName"`
Phone string `json:"phone"`
UserName string `json:"userName"`
} `json:"ext"`
IsOrg int `json:"isOrg"`
OrgCode string `json:"orgCode"`
OrgID int `json:"orgId"`
OrgName string `json:"orgName"`
OrgStatus int `json:"orgStatus"`
ParentID int `json:"parentId"`
ParentPath string `json:"parentPath"`
} `json:"org"`
}
)
//返回组织列表
type (
ReqOrgSearch struct {
CompanyId int `json:"companyId"`
DepName string `json:"depName"`
IsOrg int `json:"isOrg"`
Limit int `json:"limit"`
Offset int `json:"offset"`
OrgCode string `json:"orgCode"`
ParentId int `json:"parentId"`
}
DataOrgSearch struct {
Count int `json:"count"`
Orgs []struct {
CompanyID int `json:"companyId"`
Ext struct {
DepName string `json:"depName"`
OrgName string `json:"orgName"`
ParentDepName string `json:"parentDepName"`
Phone string `json:"phone"`
UserName string `json:"userName"`
} `json:"ext"`
IsOrg int `json:"isOrg"`
OrgCode string `json:"orgCode"`
OrgID int `json:"orgId"`
OrgName string `json:"orgName"`
OrgStatus int `json:"orgStatus"`
ParentID int `json:"parentId"`
ParentPath string `json:"parentPath"`
} `json:"orgs"`
}
)
... ...
... ... @@ -87,6 +87,7 @@ type (
}
DataRoleCreate struct {
RoleID int64 `json:"roleID"`
}
)
... ...
... ... @@ -216,7 +216,7 @@ type (
Email string `json:"email"`
}
DataCreateUser struct {
UserDetail
UserId int `json:"userId"`
}
)
... ... @@ -323,6 +323,7 @@ type (
Password string `json:"password"`
}
DataCreateCooperatorUser struct {
UserId int `json:"userId"`
}
)
... ...