作者 tangxuhui

新增gateway 菜单模块

@@ -33,7 +33,7 @@ func (usersService *UsersService) CompanyUserEnable(companyUserEnableCommand *co @@ -33,7 +33,7 @@ func (usersService *UsersService) CompanyUserEnable(companyUserEnableCommand *co
33 33
34 // 返回公司用户信息列表 34 // 返回公司用户信息列表
35 func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.CompanyUserListQuery) (int64, interface{}, error) { 35 func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.CompanyUserListQuery) (int64, interface{}, error) {
36 - creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser() 36 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(0, 0, 0)
37 result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ 37 result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
38 Offset: (companyUserListQuery.PageNumber - 1) * companyUserListQuery.PageSize, 38 Offset: (companyUserListQuery.PageNumber - 1) * companyUserListQuery.PageSize,
39 Limit: companyUserListQuery.PageSize, 39 Limit: companyUserListQuery.PageSize,
@@ -13,14 +13,13 @@ type HttplibAlliedCreationUser struct { @@ -13,14 +13,13 @@ type HttplibAlliedCreationUser struct {
13 baseUrL string 13 baseUrL string
14 } 14 }
15 15
16 -var alliedCreationUserClient = &HttplibAlliedCreationUser{  
17 - BaseServiceGateway: service_gateway.BaseServiceGateway{  
18 - ConnectTimeout: 100 * time.Second,  
19 - ReadWriteTimeout: 30 * time.Second,  
20 - },  
21 - baseUrL: constant.ALLIED_CREATION_USER_HOST,  
22 -} 16 +func NewHttplibAlliedCreationUser(companyId int64, orgId int64, userId int64) *HttplibAlliedCreationUser {
  17 + return &HttplibAlliedCreationUser{
  18 + BaseServiceGateway: service_gateway.BaseServiceGateway{
  19 + ConnectTimeout: 100 * time.Second,
  20 + ReadWriteTimeout: 30 * time.Second,
  21 + },
  22 + baseUrL: constant.ALLIED_CREATION_USER_HOST,
  23 + }
23 24
24 -func NewHttplibAlliedCreationUser() *HttplibAlliedCreationUser {  
25 - return alliedCreationUserClient  
26 } 25 }
  1 +package allied_creation_user
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "strconv"
  7 +
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
  10 +)
  11 +
  12 +// MenusCreate 创建菜单
  13 +func (gateway HttplibAlliedCreationUser) MenusCreate(param ReqMenus) (*DataMenus, error) {
  14 + url := gateway.baseUrL + "/menus"
  15 + method := "post"
  16 + req := gateway.CreateRequest(url, method)
  17 + log.Logger.Debug("向用户模块请求数据:创建菜单。", map[string]interface{}{
  18 + "api": method + ":" + url,
  19 + "param": param,
  20 + })
  21 + req, err := req.JSONBody(param)
  22 + if err != nil {
  23 + return nil, fmt.Errorf("请求创建菜单失败:%w", err)
  24 + }
  25 +
  26 + byteResult, err := req.Bytes()
  27 + if err != nil {
  28 + return nil, fmt.Errorf("获取创建菜单失败:%w", err)
  29 + }
  30 + log.Logger.Debug("获取用户模块请求数据:创建菜单。", map[string]interface{}{
  31 + "result": string(byteResult),
  32 + })
  33 + var result service_gateway.GatewayResponse
  34 + err = json.Unmarshal(byteResult, &result)
  35 + if err != nil {
  36 + return nil, fmt.Errorf("解析创建菜单:%w", err)
  37 + }
  38 + var data DataMenus
  39 + err = gateway.GetResponseData(result, &data)
  40 + return &data, err
  41 +}
  42 +
  43 +// MenusUpdate 更新菜单
  44 +func (gateway HttplibAlliedCreationUser) MenusUpdate(param ReqMenusUpdate) (*DataMenusUpdate, error) {
  45 + url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.MenusId, 10)
  46 + method := "put"
  47 + req := gateway.CreateRequest(url, method)
  48 + log.Logger.Debug("向用户模块请求数据:更新菜单。", map[string]interface{}{
  49 + "api": method + ":" + url,
  50 + "param": param,
  51 + })
  52 + req, err := req.JSONBody(param)
  53 + if err != nil {
  54 + return nil, fmt.Errorf("请求更新菜单失败:%w", err)
  55 + }
  56 +
  57 + byteResult, err := req.Bytes()
  58 + if err != nil {
  59 + return nil, fmt.Errorf("获取更新菜单失败:%w", err)
  60 + }
  61 + log.Logger.Debug("获取用户模块请求数据:更新菜单。", map[string]interface{}{
  62 + "result": string(byteResult),
  63 + })
  64 + var result service_gateway.GatewayResponse
  65 + err = json.Unmarshal(byteResult, &result)
  66 + if err != nil {
  67 + return nil, fmt.Errorf("解析更新菜单:%w", err)
  68 + }
  69 + var data DataMenusUpdate
  70 + err = gateway.GetResponseData(result, &data)
  71 + return &data, err
  72 +}
  73 +
  74 +// MenusRemove 移除菜单
  75 +func (gateway HttplibAlliedCreationUser) MenusRemove(param ReqMenusRemove) (*DataMenusRemove, error) {
  76 + url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.RoleId, 10)
  77 + method := "delete"
  78 + req := gateway.CreateRequest(url, method)
  79 + log.Logger.Debug("向用户模块请求数据:移除菜单。", map[string]interface{}{
  80 + "api": method + ":" + url,
  81 + "param": param,
  82 + })
  83 + req, err := req.JSONBody(param)
  84 + if err != nil {
  85 + return nil, fmt.Errorf("请求移除菜单失败:%w", err)
  86 + }
  87 +
  88 + byteResult, err := req.Bytes()
  89 + if err != nil {
  90 + return nil, fmt.Errorf("获取移除菜单失败:%w", err)
  91 + }
  92 + log.Logger.Debug("获取用户模块请求数据:移除菜单。", map[string]interface{}{
  93 + "result": string(byteResult),
  94 + })
  95 + var result service_gateway.GatewayResponse
  96 + err = json.Unmarshal(byteResult, &result)
  97 + if err != nil {
  98 + return nil, fmt.Errorf("解析移除菜单:%w", err)
  99 + }
  100 + var data DataMenusRemove
  101 + err = gateway.GetResponseData(result, &data)
  102 + return &data, err
  103 +}
  104 +
  105 +// MenusGet 返回菜单
  106 +func (gateway HttplibAlliedCreationUser) MenusGet(param ReqMenusGet) (*DataMenusGet, error) {
  107 + url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.MenuId, 10)
  108 + method := "get"
  109 + req := gateway.CreateRequest(url, method)
  110 + log.Logger.Debug("向用户模块请求数据:返回菜单。", map[string]interface{}{
  111 + "api": method + ":" + url,
  112 + "param": param,
  113 + })
  114 + req, err := req.JSONBody(param)
  115 + if err != nil {
  116 + return nil, fmt.Errorf("请求返回菜单失败:%w", err)
  117 + }
  118 +
  119 + byteResult, err := req.Bytes()
  120 + if err != nil {
  121 + return nil, fmt.Errorf("获取返回菜单失败:%w", err)
  122 + }
  123 + log.Logger.Debug("获取用户模块请求数据:返回菜单。", map[string]interface{}{
  124 + "result": string(byteResult),
  125 + })
  126 + var result service_gateway.GatewayResponse
  127 + err = json.Unmarshal(byteResult, &result)
  128 + if err != nil {
  129 + return nil, fmt.Errorf("解析返回菜单:%w", err)
  130 + }
  131 + var data DataMenusGet
  132 + err = gateway.GetResponseData(result, &data)
  133 + return &data, err
  134 +}
  135 +
  136 +// MenusSearch 返回菜单列表
  137 +func (gateway HttplibAlliedCreationUser) MenusSearch(param ReqMenusSearch) (*DataMenusSearch, error) {
  138 + url := gateway.baseUrL + "/menus/search"
  139 + method := "post"
  140 + req := gateway.CreateRequest(url, method)
  141 + log.Logger.Debug("向用户模块请求数据:返回菜单列表。", map[string]interface{}{
  142 + "api": method + ":" + url,
  143 + "param": param,
  144 + })
  145 + req, err := req.JSONBody(param)
  146 + if err != nil {
  147 + return nil, fmt.Errorf("请求返回菜单列表失败:%w", err)
  148 + }
  149 +
  150 + byteResult, err := req.Bytes()
  151 + if err != nil {
  152 + return nil, fmt.Errorf("获取返回菜单列表失败:%w", err)
  153 + }
  154 + log.Logger.Debug("获取用户模块请求数据:返回菜单列表。", map[string]interface{}{
  155 + "result": string(byteResult),
  156 + })
  157 + var result service_gateway.GatewayResponse
  158 + err = json.Unmarshal(byteResult, &result)
  159 + if err != nil {
  160 + return nil, fmt.Errorf("解析返回菜单列表:%w", err)
  161 + }
  162 + var data DataMenusSearch
  163 + err = gateway.GetResponseData(result, &data)
  164 + return &data, err
  165 +}
@@ -105,8 +105,8 @@ func (gateway HttplibAlliedCreationUser) RoleAssign(param ReqRoleAssign) (*DataR @@ -105,8 +105,8 @@ func (gateway HttplibAlliedCreationUser) RoleAssign(param ReqRoleAssign) (*DataR
105 return &data, err 105 return &data, err
106 } 106 }
107 107
108 -// Role 创建角色  
109 -func (gateway HttplibAlliedCreationUser) Role(param ReqRole) (*DataRole, error) { 108 +// RoleCreate 创建角色
  109 +func (gateway HttplibAlliedCreationUser) RoleCreate(param ReqRole) (*DataRole, error) {
110 urlStr := gateway.baseUrL + "/role" 110 urlStr := gateway.baseUrL + "/role"
111 method := "post" 111 method := "post"
112 req := gateway.CreateRequest(urlStr, method) 112 req := gateway.CreateRequest(urlStr, method)
  1 +package allied_creation_user
  2 +
  3 +//创建菜单
  4 +type (
  5 + ReqMenus struct {
  6 + }
  7 +
  8 + DataMenus struct {
  9 + }
  10 +)
  11 +
  12 +//更新菜单
  13 +type (
  14 + ReqMenusUpdate struct {
  15 + MenusId int64
  16 + }
  17 +
  18 + DataMenusUpdate struct {
  19 + }
  20 +)
  21 +
  22 +//移除菜单
  23 +type (
  24 + ReqMenusRemove struct {
  25 + RoleId int64
  26 + }
  27 +
  28 + DataMenusRemove struct {
  29 + }
  30 +)
  31 +
  32 +//返回菜单
  33 +type (
  34 + ReqMenusGet struct {
  35 + MenuId int64
  36 + }
  37 +
  38 + DataMenusGet struct {
  39 + }
  40 +)
  41 +
  42 +//返回菜单列表
  43 +type (
  44 + ReqMenusSearch struct {
  45 + }
  46 +
  47 + DataMenusSearch struct {
  48 + }
  49 +)