作者 tangxuhui

新增 gateway 公司、组织模块

  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 +// CompanyCreate 创建企业
  13 +func (gateway HttplibAlliedCreationUser) CompanyCreate(param ReqCompanyCreate) (*DataCompanyCreate, error) {
  14 + url := gateway.baseUrL + "/company"
  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 DataCompanyCreate
  39 + err = gateway.GetResponseData(result, &data)
  40 + return &data, err
  41 +}
  42 +
  43 +//CompanyUpdate 更新企业
  44 +func (gateway HttplibAlliedCreationUser) CompanyUpdate(param ReqCompanyUpdate) (*DataCompanyUpdate, error) {
  45 + url := gateway.baseUrL + "/company/" + strconv.FormatInt(param.CompanyId, 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 DataCompanyUpdate
  70 + err = gateway.GetResponseData(result, &data)
  71 + return &data, err
  72 +}
  73 +
  74 +// CompanySetCustomizeMenus 更新自定义菜单
  75 +func (gateway HttplibAlliedCreationUser) CompanySetCustomizeMenus(param ReqCompanySetCustomizeMenus) (*DataCompanySetCustomizeMenus, error) {
  76 + url := gateway.baseUrL + "/company/" + strconv.FormatInt(param.CompanyId, 10) + "/customize-menus"
  77 + method := "put"
  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 DataCompanySetCustomizeMenus
  101 + err = gateway.GetResponseData(result, &data)
  102 + return &data, err
  103 +}
  104 +
  105 +// CompanyRemove 移除企业
  106 +func (gateway HttplibAlliedCreationUser) CompanyRemove(param ReqCompanyRemove) (*DataCompanyRemove, error) {
  107 + url := gateway.baseUrL + "/company/" + strconv.FormatInt(param.CompanyId, 10)
  108 + method := "delete"
  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 DataCompanyRemove
  132 + err = gateway.GetResponseData(result, &data)
  133 + return &data, err
  134 +}
  135 +
  136 +// CompanyGet 返回企业
  137 +func (gateway HttplibAlliedCreationUser) CompanyGet(param ReqCompanyGet) (*DataCompanyGet, error) {
  138 + url := gateway.baseUrL + "/company/{companyId}"
  139 + method := "GET"
  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 DataCompanyGet
  163 + err = gateway.GetResponseData(result, &data)
  164 + return &data, err
  165 +}
  166 +
  167 +// CompanySearch 返回企业列表
  168 +func (gateway HttplibAlliedCreationUser) CompanySearch(param ReqCompanySearch) (*DataCompanySearch, error) {
  169 + url := gateway.baseUrL + "/company/search"
  170 + method := "post"
  171 + req := gateway.CreateRequest(url, method)
  172 + log.Logger.Debug("向用户模块请求数据:返回企业列表。", map[string]interface{}{
  173 + "api": method + ":" + url,
  174 + "param": param,
  175 + })
  176 + req, err := req.JSONBody(param)
  177 + if err != nil {
  178 + return nil, fmt.Errorf("请求返回企业列表失败:%w", err)
  179 + }
  180 +
  181 + byteResult, err := req.Bytes()
  182 + if err != nil {
  183 + return nil, fmt.Errorf("获取返回企业列表失败:%w", err)
  184 + }
  185 + log.Logger.Debug("获取用户模块请求数据:返回企业列表。", map[string]interface{}{
  186 + "result": string(byteResult),
  187 + })
  188 + var result service_gateway.GatewayResponse
  189 + err = json.Unmarshal(byteResult, &result)
  190 + if err != nil {
  191 + return nil, fmt.Errorf("解析返回企业列表:%w", err)
  192 + }
  193 + var data DataCompanySearch
  194 + err = gateway.GetResponseData(result, &data)
  195 + return &data, err
  196 +}
  197 +
  198 +// CompanyGetCustomizeMenus 返回自定义菜单列表
  199 +func (gateway HttplibAlliedCreationUser) CompanyGetCustomizeMenus(param ReqCompanyGetCustomizeMenus) (*DataCompanyGetCustomizeMenus, error) {
  200 + url := gateway.baseUrL + "/company/" + strconv.FormatInt(param.CompanyId, 10) + "/customize-menus"
  201 + method := "get"
  202 + req := gateway.CreateRequest(url, method)
  203 + log.Logger.Debug("向用户模块请求数据:返回自定义菜单列表。", map[string]interface{}{
  204 + "api": method + ":" + url,
  205 + "param": param,
  206 + })
  207 + req, err := req.JSONBody(param)
  208 + if err != nil {
  209 + return nil, fmt.Errorf("请求返回自定义菜单列表失败:%w", err)
  210 + }
  211 +
  212 + byteResult, err := req.Bytes()
  213 + if err != nil {
  214 + return nil, fmt.Errorf("获取返回自定义菜单列表失败:%w", err)
  215 + }
  216 + log.Logger.Debug("获取用户模块请求数据:返回自定义菜单列表。", map[string]interface{}{
  217 + "result": string(byteResult),
  218 + })
  219 + var result service_gateway.GatewayResponse
  220 + err = json.Unmarshal(byteResult, &result)
  221 + if err != nil {
  222 + return nil, fmt.Errorf("解析返回自定义菜单列表:%w", err)
  223 + }
  224 + var data DataCompanyGetCustomizeMenus
  225 + err = gateway.GetResponseData(result, &data)
  226 + return &data, err
  227 +}
  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 +// Org 创建组织
  13 +func (gateway HttplibAlliedCreationUser) OrgCreate(param ReqOrg) (*DataOrg, error) {
  14 + url := gateway.baseUrL + "/org"
  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 DataOrg
  39 + err = gateway.GetResponseData(result, &data)
  40 + return &data, err
  41 +}
  42 +
  43 +//OrgUpdate 更新组织
  44 +func (gateway HttplibAlliedCreationUser) OrgUpdate(param ReqOrgUpdate) (*DataOrgUpdate, error) {
  45 + url := gateway.baseUrL + "/org/" + strconv.FormatInt(param.OrgId, 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 DataOrgUpdate
  70 + err = gateway.GetResponseData(result, &data)
  71 + return &data, err
  72 +}
  73 +
  74 +// Org[orgId} 移除组织
  75 +func (gateway HttplibAlliedCreationUser) OrgRemove(param ReqOrgRemove) (*DataOrgRemove, error) {
  76 + url := gateway.baseUrL + "/org/" + strconv.FormatInt(param.OrgId, 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 DataOrgRemove
  101 + err = gateway.GetResponseData(result, &data)
  102 + return &data, err
  103 +}
  104 +
  105 +// Org[orgId}Sub-department 获取组织的子部门(通用部门列表使用)
  106 +func (gateway HttplibAlliedCreationUser) OrgGetSubDepartment(param ReqOrgGetSubDepartment) (*DataOrgGetSubDepartment, error) {
  107 + url := gateway.baseUrL + "/org/" + strconv.FormatInt(param.OrgId, 10) + "/sub-department"
  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 DataOrgGetSubDepartment
  132 + err = gateway.GetResponseData(result, &data)
  133 + return &data, err
  134 +}
  135 +
  136 +// OrgEnable 设置组织启用状态
  137 +func (gateway HttplibAlliedCreationUser) OrgEnable(param ReqOrgEnable) (*DataOrgEnable, error) {
  138 + url := gateway.baseUrL + "/org/enable"
  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 DataOrgEnable
  163 + err = gateway.GetResponseData(result, &data)
  164 + return &data, err
  165 +}
  166 +
  167 +// Org[orgId} 返回组织
  168 +func (gateway HttplibAlliedCreationUser) OrgGet(param ReqOrgGet) (*DataOrgGet, error) {
  169 + url := gateway.baseUrL + "/org/" + strconv.FormatInt(param.OrgId, 10)
  170 + method := "get"
  171 + req := gateway.CreateRequest(url, method)
  172 + log.Logger.Debug("向用户模块请求数据:返回组织。", map[string]interface{}{
  173 + "api": method + ":" + url,
  174 + "param": param,
  175 + })
  176 + req, err := req.JSONBody(param)
  177 + if err != nil {
  178 + return nil, fmt.Errorf("请求返回组织失败:%w", err)
  179 + }
  180 +
  181 + byteResult, err := req.Bytes()
  182 + if err != nil {
  183 + return nil, fmt.Errorf("获取返回组织失败:%w", err)
  184 + }
  185 + log.Logger.Debug("获取用户模块请求数据:返回组织。", map[string]interface{}{
  186 + "result": string(byteResult),
  187 + })
  188 + var result service_gateway.GatewayResponse
  189 + err = json.Unmarshal(byteResult, &result)
  190 + if err != nil {
  191 + return nil, fmt.Errorf("解析返回组织:%w", err)
  192 + }
  193 + var data DataOrgGet
  194 + err = gateway.GetResponseData(result, &data)
  195 + return &data, err
  196 +}
  197 +
  198 +// OrgSearch 返回组织列表
  199 +func (gateway HttplibAlliedCreationUser) OrgSearch(param ReqOrgSearch) (*DataOrgSearch, error) {
  200 + url := gateway.baseUrL + "/org/search"
  201 + method := "post"
  202 + req := gateway.CreateRequest(url, method)
  203 + log.Logger.Debug("向用户模块请求数据:返回组织列表。", map[string]interface{}{
  204 + "api": method + ":" + url,
  205 + "param": param,
  206 + })
  207 + req, err := req.JSONBody(param)
  208 + if err != nil {
  209 + return nil, fmt.Errorf("请求返回组织列表失败:%w", err)
  210 + }
  211 +
  212 + byteResult, err := req.Bytes()
  213 + if err != nil {
  214 + return nil, fmt.Errorf("获取返回组织列表失败:%w", err)
  215 + }
  216 + log.Logger.Debug("获取用户模块请求数据:返回组织列表。", map[string]interface{}{
  217 + "result": string(byteResult),
  218 + })
  219 + var result service_gateway.GatewayResponse
  220 + err = json.Unmarshal(byteResult, &result)
  221 + if err != nil {
  222 + return nil, fmt.Errorf("解析返回组织列表:%w", err)
  223 + }
  224 + var data DataOrgSearch
  225 + err = gateway.GetResponseData(result, &data)
  226 + return &data, err
  227 +}
  1 +package allied_creation_user
  2 +
  3 +//创建企业
  4 +type (
  5 + ReqCompanyCreate struct {
  6 + }
  7 +
  8 + DataCompanyCreate struct {
  9 + }
  10 +)
  11 +
  12 +//更新企业
  13 +type (
  14 + ReqCompanyUpdate struct {
  15 + CompanyId int64
  16 + }
  17 +
  18 + DataCompanyUpdate struct {
  19 + }
  20 +)
  21 +
  22 +//更新自定义菜单
  23 +type (
  24 + ReqCompanySetCustomizeMenus struct {
  25 + CompanyId int64
  26 + }
  27 +
  28 + DataCompanySetCustomizeMenus struct {
  29 + }
  30 +)
  31 +
  32 +//移除企业
  33 +type (
  34 + ReqCompanyRemove struct {
  35 + CompanyId int64
  36 + }
  37 +
  38 + DataCompanyRemove struct {
  39 + }
  40 +)
  41 +
  42 +//返回企业
  43 +type (
  44 + ReqCompanyGet struct {
  45 + }
  46 +
  47 + DataCompanyGet struct {
  48 + }
  49 +)
  50 +
  51 +//返回企业列表
  52 +type (
  53 + ReqCompanySearch struct {
  54 + }
  55 +
  56 + DataCompanySearch struct {
  57 + }
  58 +)
  59 +
  60 +//返回自定义菜单列表
  61 +type (
  62 + ReqCompanyGetCustomizeMenus struct {
  63 + CompanyId int64
  64 + }
  65 +
  66 + DataCompanyGetCustomizeMenus struct {
  67 + }
  68 +)
  1 +package allied_creation_user
  2 +
  3 +//创建组织
  4 +type (
  5 + ReqOrg struct {
  6 + }
  7 +
  8 + DataOrg struct {
  9 + }
  10 +)
  11 +
  12 +//更新组织
  13 +type (
  14 + ReqOrgUpdate struct {
  15 + OrgId int64
  16 + }
  17 +
  18 + DataOrgUpdate struct {
  19 + }
  20 +)
  21 +
  22 +//移除组织
  23 +type (
  24 + ReqOrgRemove struct {
  25 + OrgId int64
  26 + }
  27 +
  28 + DataOrgRemove struct {
  29 + }
  30 +)
  31 +
  32 +//获取组织的子部门(通用部门列表使用)
  33 +type (
  34 + ReqOrgGetSubDepartment struct {
  35 + OrgId int64
  36 + }
  37 +
  38 + DataOrgGetSubDepartment struct {
  39 + }
  40 +)
  41 +
  42 +//设置组织启用状态
  43 +type (
  44 + ReqOrgEnable struct {
  45 + }
  46 +
  47 + DataOrgEnable struct {
  48 + }
  49 +)
  50 +
  51 +//返回组织
  52 +type (
  53 + ReqOrgGet struct {
  54 + OrgId int64
  55 + }
  56 +
  57 + DataOrgGet struct {
  58 + }
  59 +)
  60 +
  61 +//返回组织列表
  62 +type (
  63 + ReqOrgSearch struct {
  64 + }
  65 +
  66 + DataOrgSearch struct {
  67 + }
  68 +)