作者 tangxuhui

更新 代码结构

正在显示 37 个修改的文件 包含 851 行增加96 行删除
不能预览此文件类型
{"D:\\workspaceGo\\src\\allied-creation-gateway\\pkg\\port\\beego":1627356799005386400}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@ package main
import (
"github.com/beego/beego/v2/server/web"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego"
)
func main() {
... ...
package query
type GetDictionaryByCodeQuery struct {
DictCode []string `json:"dictCode"`
}
... ...
package service
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
)
type CommonService struct {
}
func NewCommonService(options map[string]interface{}) *CommonService {
return &CommonService{}
}
//GetDictionaryByCode 根据code获取字典数据
func (dictionaryService *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDictionaryByCodeQuery) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic()
result, err := creationBasicGateway.GetDictionarysByCode(allied_creation_basic.ReqGetDictionaryByCode{
DictCode: getDictionaryQuery.DictCode,
})
if err != nil {
return nil, err
}
return result, nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type CompanyUserAddCommand struct {
// 用户编号
UsersCode string `json:"usersCode" valid:"Required"`
// 用户姓名
UsersName string `json:"usersName" valid:"Required"`
// 组织ID
OrgId int64 `json:"orgId" valid:"Required"`
// 部门id
DepartmentId int64 `json:"departmentId" valid:"Required"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `json:"enableStatus" valid:"Required"`
// 手机号码
Phone string `json:"phone" valid:"Required"`
// 邮箱
Email string `json:"email" valid:"Required"`
// 关联的组织机构
UsersOrg []int64 `json:"usersOrg,omitempty"`
// 关联的用户
UsersRole []int64 `json:"usersRole,omitempty"`
// 头像
Avator string `json:"avator" valid:"Required"`
}
func (companyUserAddCommand *CompanyUserAddCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (companyUserAddCommand *CompanyUserAddCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(companyUserAddCommand)
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"
)
type CompanyUserEnableCommand struct {
UsersIds []int64 `json:"usersIds,omitempty"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `json:"enableStatus,omitempty"`
}
func (companyUserEnableCommand *CompanyUserEnableCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (companyUserEnableCommand *CompanyUserEnableCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(companyUserEnableCommand)
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"
)
type CompanyUserResetPasswordCommand struct {
UsersIds []int64 `json:"usersIds" valid:"Required"`
}
func (companyUserResetPasswordCommand *CompanyUserResetPasswordCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (companyUserResetPasswordCommand *CompanyUserResetPasswordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(companyUserResetPasswordCommand)
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"
)
type CompanyUserUpdateCommand struct {
UsersId int64 `json:"usersId" valid:"Required"`
// 用户编号
UsersCode string `json:"usersCode,omitempty"`
// 用户名称
UsersName string `json:"usersName,omitempty"`
// 组织机构id
OrganizationId int64 `json:"organizationId,omitempty"`
// 部门id
DepartmentId int64 `json:"departmentId,omitempty"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `json:"enableStatus,omitempty"`
// 手机号
Phone string `json:"phone,omitempty"`
// 邮箱
Email string `json:"email,omitempty"`
// 关联的组织机构
UsersOrg []int64 `json:"usersOrg,omitempty"`
// 关联的组织结构
UsersRole []int64 `json:"usersRole,omitempty"`
// 头像
Avator string `json:"avator,omitempty"`
}
func (companyUserUpdateCommand *CompanyUserUpdateCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (companyUserUpdateCommand *CompanyUserUpdateCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(companyUserUpdateCommand)
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"
)
type CooperationUserAddCommand struct {
// 用户编号
UsersId int64 `json:"usersId" valid:"Required"`
// 用户编号
UsersCode string `json:"usersCode" valid:"Required"`
// 用户姓名
UsersName string `json:"usersName" valid:"Required"`
// 共创公司
CooperationCompany string `json:"cooperationCompany" valid:"Required"`
// 共创公司到期时间
CooperationDeadline string `json:"cooperationDeadline" valid:"Required"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `json:"enableStatus" valid:"Required"`
// 邮箱
Email string `json:"email" valid:"Required"`
}
func (cooperationUserAddCommand *CooperationUserAddCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (cooperationUserAddCommand *CooperationUserAddCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cooperationUserAddCommand)
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"
)
type CooperationUserEnableCommand struct {
UsersIds []int64 `json:"usersIds,omitempty"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `json:"enableStatus,omitempty"`
}
func (cooperationUserEnableCommand *CooperationUserEnableCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (cooperationUserEnableCommand *CooperationUserEnableCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cooperationUserEnableCommand)
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"
)
type CooperationUserResetPasswordCommand struct {
UsersIds []int64 `json:"usersIds" valid:"Required"`
}
func (cooperationUserResetPasswordCommand *CooperationUserResetPasswordCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (cooperationUserResetPasswordCommand *CooperationUserResetPasswordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cooperationUserResetPasswordCommand)
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"
)
type CooperationUserUpdateCommand struct {
// 用户编号
UsersId int64 `json:"usersId" valid:"Required"`
// 用户编号
UsersCode string `json:"usersCode" valid:"Required"`
// 用户姓名
UsersName string `json:"usersName" valid:"Required"`
// 共创公司
CooperationCompany string `json:"cooperationCompany" valid:"Required"`
// 共创公司到期时间
CooperationDeadline string `json:"cooperationDeadline" valid:"Required"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `json:"enableStatus" valid:"Required"`
// 邮箱
Email string `json:"email" valid:"Required"`
}
func (cooperationUserUpdateCommand *CooperationUserUpdateCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (cooperationUserUpdateCommand *CooperationUserUpdateCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cooperationUserUpdateCommand)
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"
)
type CompanyUserGetQuery struct {
// 用户编号
UsersId int64 `json:"usersId" valid:"Required"`
}
func (companyUserGetQuery *CompanyUserGetQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (companyUserGetQuery *CompanyUserGetQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(companyUserGetQuery)
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"
)
type CompanyUserListQuery struct {
// 页码
PageNumber int `json:"pageNumber"`
// 每页数量
PageSize int `json:"pageSize" valid:"Required"`
}
func (companyUserListQuery *CompanyUserListQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (companyUserListQuery *CompanyUserListQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(companyUserListQuery)
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"
)
type CooperationUserGetQuery struct {
// 用户编号
UsersId int64 `json:"usersId" valid:"Required"`
}
func (cooperationUserGetQuery *CooperationUserGetQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (cooperationUserGetQuery *CooperationUserGetQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cooperationUserGetQuery)
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"
)
type CooperationUserListQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
func (cooperationUserListQuery *CooperationUserListQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (cooperationUserListQuery *CooperationUserListQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cooperationUserListQuery)
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 (
"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"
)
// 用户信息
type UsersService struct {
}
// 获取公司用户信息
func (usersService *UsersService) CompanyUserGet(companyUserGetQuery *query.CompanyUserGetQuery) (interface{}, error) {
return nil, nil
}
// 创建公司用户信息
func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.CompanyUserAddCommand) (interface{}, error) {
return nil, nil
}
// 启用禁用公司用户信息
func (usersService *UsersService) CompanyUserEnable(companyUserEnableCommand *command.CompanyUserEnableCommand) (interface{}, error) {
return nil, nil
}
// 返回公司用户信息列表
func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.CompanyUserListQuery) (interface{}, error) {
return nil, nil
}
// 批量重置密码
func (usersService *UsersService) CompanyUserResetPassword(companyUserResetPasswordCommand *command.CompanyUserResetPasswordCommand) (interface{}, error) {
return nil, nil
}
// 更新公司用户信息
func (usersService *UsersService) CompanyUserUpdate(companyUserUpdateCommand *command.CompanyUserUpdateCommand) (interface{}, error) {
return nil, nil
}
// 创建共创用户信息
func (usersService *UsersService) CooperationUserAdd(cooperationUserAddCommand *command.CooperationUserAddCommand) (interface{}, error) {
return nil, nil
}
// 启用禁用共创用户信息
func (usersService *UsersService) CooperationUserEnable(cooperationUserEnableCommand *command.CooperationUserEnableCommand) (interface{}, error) {
return nil, nil
}
// 获取共创用户信息
func (usersService *UsersService) CooperationUserGet(cooperationUserGetQuery *query.CooperationUserGetQuery) (interface{}, error) {
return nil, nil
}
// 返回共创用户信息列表
func (usersService *UsersService) CooperationUserList(cooperationUserListQuery *query.CooperationUserListQuery) (interface{}, error) {
return nil, nil
}
// 批量重置密码
func (usersService *UsersService) CooperationUserResetPassword(cooperationUserResetPasswordCommand *command.CooperationUserResetPasswordCommand) (interface{}, error) {
return nil, nil
}
// 编辑共创用户信息
func (usersService *UsersService) CooperationUserUpdate(cooperationUserUpdateCommand *command.CooperationUserUpdateCommand) (interface{}, error) {
return nil, nil
}
func NewUsersService(options map[string]interface{}) *UsersService {
newUsersService := &UsersService{}
return newUsersService
}
... ...
... ... @@ -8,6 +8,8 @@ var LOG_LEVEL = "debug"
var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080"
var ALLIED_CREATION_USER_HOST = "http://localhost:8080"
func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
... ... @@ -15,4 +17,7 @@ func init() {
if os.Getenv("ALLIED_CREATION_BASIC_HOST") != "" {
ALLIED_CREATION_BASIC_HOST = os.Getenv("ALLIED_CREATION_BASIC_HOST")
}
if os.Getenv("ALLIED_CREATION_USER_HOST") != "" {
ALLIED_CREATION_USER_HOST = os.Getenv("ALLIED_CREATION_USER_HOST")
}
}
... ...
package domain
import "time"
// 公司信息
type CompanyInfo struct {
// 企业名称
CompanyName string `json:"companyName"`
// 规模
Scale string `json:"scale"`
// 公司Logo地址
Logo string `json:"logo"`
// 地址
Address string `json:"address"`
// 所属行业
IndustryCategory string `json:"industryCategory"`
// 联系人
Contacts string `json:"contacts"`
// 注册时间
RegistTime time.Time `json:"registTime"`
// 注册状态 1:已注册 2:待认证 3:已认证
RegistStatus int `json:"registStatus"`
}
... ...
package domain
// 部门
type Department struct {
// 组织ID
OrgId int64 `json:"orgId"`
// 组织名称
OrgName string `json:"orgName"`
// 组织编码
OrgCode string `json:"orgCode"`
// 父级id
ParentId int64 `json:"parentId"`
}
... ...
package domain
// 系统菜单
type Menu struct {
// 菜单编号
MenuId int64 `json:"menuId"`
// 父级id
ParentId int64 `json:"parentId"`
// 菜单名称
MenuName string `json:"menuName"`
// 菜单别名
MenuAlias string `json:"menuAlias"`
// 菜单编码 SYSTEM_USER_EDIT
Code string `json:"code"`
// 菜单类型 (目录catalog、菜单menu、按钮button)
MenuType string `json:"menuType"`
// 菜单图标
Icon string `json:"icon"`
// 排序
Sort int `json:"sort"`
// 菜单说明
Remark string `json:"remark"`
// 菜单类别 (web:1、app:2)
Category string `json:"category"`
}
... ...
package domain
// 组织organization
type Orgs struct {
// 组织ID
OrgId int64 `json:"orgId"`
// 企业id
CompanyId int64 `json:"companyId"`
// 组织编码
OrgCode string `json:"orgCode"`
// 组织名称
OrgName string `json:"orgName"`
IsOrg string `json:"isOrg"`
// 父级id
ParentId int64 `json:"parentId"`
}
... ...
package domain
// 区域信息值对象
type RegionInfo struct {
// 区域编号
RegionNumber string `json:"regionNumber"`
// 区域名称
RegionName string `json:"regionName"`
}
... ...
package domain
// 用户基础信息
type Users struct {
// 用户id
UserId string `json:"userId"`
// 用户基础信息
UserInfo *UsersBase `json:"userInfo,omitempty"`
// 用户的组织
Org *Orgs `json:"org,omitempty"`
// 用户的部门
Department *Department `json:"department,omitempty"`
}
... ...
package domain
// 用户基础信息
type UsersBase struct {
// 手机号码
Phone string `json:"phone"`
// 共创模式状态,1启用,2禁用
Status int32 `json:"status"`
// 用户编号
UsersCode string `json:"usersCode"`
// 用户编号
UsersId int64 `json:"usersId"`
// 用户姓名
UsersName string `json:"usersName"`
// 邮箱
Email string `json:"email"`
// 共创公司
CooperationCompany string `json:"cooperationCompany"`
// 共创公司到期时间
CooperationDeadline string `json:"cooperationDeadline"`
}
... ...
package service_gateway
package allied_creation_basic
import (
"encoding/json"
"fmt"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
type HttplibAlliedCreationBasic struct {
BaseServiceGateway
BaseUrL string
service_gateway.BaseServiceGateway
baseUrL string
}
var alliedCreationBasicClient = &HttplibAlliedCreationBasic{
BaseServiceGateway: BaseServiceGateway{
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
BaseServiceGateway: service_gateway.BaseServiceGateway{
ConnectTimeout: 100 * time.Second,
ReadWriteTimeout: 30 * time.Second,
},
BaseUrL: "",
baseUrL: constant.ALLIED_CREATION_BASIC_HOST,
}
func NewHttplibAlliedCreationBasic() *HttplibAlliedCreationBasic {
return alliedCreationBasicClient
}
//ReqGetDictionarysByCode 根据code获取字典数据
type ReqGetDictionarysByCode struct {
DictCode string `json:"dictCode"`
}
//DataGetDictionarysByCode 根据code获取字典数据
type DataGetDictionarysByCode struct {
Dictionarys []domain.Dictionary `json:"dictionarys"`
}
//GetDictionarysByCode 根据code获取字典数据
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDictionarysByCode) (*DataGetDictionarysByCode, error) {
url := gateway.BaseUrL + "/dictionarys/dictionary-code"
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDictionaryByCode) (*DataGetDictionaryByCode, error) {
url := gateway.baseUrL + "/dictionarys/dictionary-code"
method := "post"
req := gateway.createRequest(url, method)
req := gateway.CreateRequest(url, method)
//TODO traceID
log.Logger.Debug("向基础模块请求数据:根据code获取字典数据。", map[string]interface{}{
"api": method + ":" + url,
... ... @@ -47,19 +40,22 @@ func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDicti
})
req, err := req.JSONBody(param)
if err != nil {
return nil, err
return nil, fmt.Errorf("请求字典数据失败:%w", err)
}
var result GatewayResponse
err = req.ToJSON(&result)
byteResult, err := req.Bytes()
if err != nil {
return nil, err
return nil, fmt.Errorf("获取字典数据失败:%w", err)
}
var data DataGetDictionarysByCode
err = gateway.getResponseData(result, &data)
log.Logger.Debug("获取基础模块响应数据:根据code获取字典数据。", map[string]interface{}{
"code": result.Code,
"msg": result.Msg,
"data": data,
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析字典数据失败:%w", err)
}
var data DataGetDictionaryByCode
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package allied_creation_basic
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
//ReqGetDictionarysByCode 根据code获取字典数据
type ReqGetDictionaryByCode struct {
DictCode []string `json:"dictCode"`
}
//DataGetDictionarysByCode 根据code获取字典数据
type DataGetDictionaryByCode struct {
Dictionarys []domain.Dictionary `json:"dictionarys"`
}
... ...
package allied_creation_user
import (
"encoding/json"
"fmt"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
//HttplibAlliedCreationUser 用户模块
type HttplibAlliedCreationUser struct {
service_gateway.BaseServiceGateway
baseUrL string
}
var alliedCreationUserClient = &HttplibAlliedCreationUser{
BaseServiceGateway: service_gateway.BaseServiceGateway{
ConnectTimeout: 100 * time.Second,
ReadWriteTimeout: 30 * time.Second,
},
baseUrL: constant.ALLIED_CREATION_USER_HOST,
}
func NewHttplibAlliedCreationUser() *HttplibAlliedCreationUser {
return alliedCreationUserClient
}
//UserSearch 搜索用户列表
func (gateway HttplibAlliedCreationUser) UserSearch(param ReqUserSearch) (*DataUserSearch, error) {
url := gateway.baseUrL + "/dictionarys/dictionary-code"
method := "post"
req := gateway.CreateRequest(url, method)
//TODO traceID
log.Logger.Debug("向用户模块请求数据:搜索用户列表。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("搜索用户列表失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取搜索用户列表失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:搜索用户列表。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析搜索用户列表:%w", err)
}
var data DataUserSearch
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package allied_creation_user
import "time"
//ReqUserSearch 搜索用户列表
type ReqUserSearch struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
// //DataUserSearch 搜索用户列表
type DataUserSearch struct {
Count int `json:"count"`
Users []struct {
UserID int `json:"userId"`
CompanyID int `json:"companyId"`
UserBaseID int `json:"userBaseId"`
UserType int `json:"userType"`
UserCode string `json:"userCode"`
OrganizationID int `json:"organizationId"`
DepartmentID int `json:"departmentId"`
UserOrg []struct {
OrgID int `json:"orgId"`
OrgName string `json:"orgName"`
} `json:"userOrg"`
UserRole []struct {
RoleID int `json:"roleId"`
RoleName string `json:"roleName"`
Ext struct {
OrgName string `json:"orgName"`
} `json:"ext"`
} `json:"userRole"`
CooperationInfo struct {
CooperationCompany string `json:"cooperationCompany"`
CooperationDeadline time.Time `json:"cooperationDeadline"`
} `json:"cooperationInfo"`
EnableStatus int `json:"enableStatus"`
Ext struct {
OrgName string `json:"orgName"`
Phone string `json:"phone"`
DepName string `json:"depName"`
} `json:"ext"`
} `json:"users"`
}
... ...
... ... @@ -8,19 +8,23 @@ import (
"github.com/beego/beego/v2/client/httplib"
)
type MessageCode struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
//GatewayResponse 统一消息返回格式
type GatewayResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
MessageCode
Data json.RawMessage `json:"data"`
}
type BaseServiceGateway struct {
connectTimeout time.Duration
readWriteTimeout time.Duration
ConnectTimeout time.Duration
ReadWriteTimeout time.Duration
}
func (gateway BaseServiceGateway) createRequest(url string, method string) *httplib.BeegoHTTPRequest {
func (gateway BaseServiceGateway) CreateRequest(url string, method string) *httplib.BeegoHTTPRequest {
var request *httplib.BeegoHTTPRequest
switch method {
case "get":
... ... @@ -36,10 +40,10 @@ func (gateway BaseServiceGateway) createRequest(url string, method string) *http
default:
request = httplib.Get(url)
}
return request.SetTimeout(gateway.connectTimeout, gateway.readWriteTimeout)
return request.SetTimeout(gateway.ConnectTimeout, gateway.ReadWriteTimeout)
}
func (gateway BaseServiceGateway) getResponseData(result GatewayResponse, data interface{}) error {
func (gateway BaseServiceGateway) GetResponseData(result GatewayResponse, data interface{}) error {
if result.Code != 0 {
return fmt.Errorf(result.Msg)
}
... ...
... ... @@ -7,8 +7,8 @@ import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
//_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/routers"
. "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/routers"
)
func init() {
... ... @@ -28,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))
}
... ...
package common_controller
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/service"
)
type CommonController struct {
beego.BaseController
}
func (controller *CommonController) GetDictionaryByCode() {
commonService := service.NewCommonService(nil)
queryParm := query.GetDictionaryByCodeQuery{}
_ = controller.Unmarshal(queryParm)
data, err := commonService.GetDictionaryByCode(&queryParm)
controller.Response(data, err)
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/loginAccess/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/loginAccess/service"
)
type LoginAccessController struct {
beego.BaseController
}
func (controller *LoginAccessController) LoginByAccount() {
loginAccessService := service.NewLoginAccessService(nil)
loginByAccountQuery := &query.LoginByAccountQuery{}
data, err := loginAccessService.LoginByAccount(loginByAccountQuery)
controller.Response(data, err)
}
func (controller *LoginAccessController) LoginBySmsCode() {
loginAccessService := service.NewLoginAccessService(nil)
loginBySmsCodeQuery := &query.LoginBySmsCodeQuery{}
data, err := loginAccessService.LoginBySmsCode(loginBySmsCodeQuery)
controller.Response(data, err)
}
func (controller *LoginAccessController) LoginByScanQrcode() {
loginAccessService := service.NewLoginAccessService(nil)
loginByScanQrcodeQuery := &query.LoginByScanQrcodeQuery{}
data, err := loginAccessService.LoginByScanQrcode(loginByScanQrcodeQuery)
controller.Response(data, err)
}
func (controller *LoginAccessController) GetQrcodeForLogin() {
loginAccessService := service.NewLoginAccessService(nil)
getQrcodeForLoginQuery := &query.GetQrcodeForLoginQuery{}
data, err := loginAccessService.GetQrcodeForLogin(getQrcodeForLoginQuery)
controller.Response(data, err)
}
func (controller *LoginAccessController) LoginInfoByAuthCode() {
loginAccessService := service.NewLoginAccessService(nil)
loginInfoByAuthCodeQuery := &query.LoginInfoByAuthCodeQuery{}
data, err := loginAccessService.LoginInfoByAuthCode(loginInfoByAuthCodeQuery)
controller.Response(data, err)
}
... ... @@ -2,13 +2,9 @@ package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/common_controller"
)
func init() {
web.Router("/auth/by-account", &controllers.LoginAccessController{}, "Post:LoginByAccount")
web.Router("/auth/by-smscode", &controllers.LoginAccessController{}, "Post:LoginBySmsCode")
web.Router("/auth/by-qrcode", &controllers.LoginAccessController{}, "Get:LoginByScanQrcode")
web.Router("/auth/get-qrcode", &controllers.LoginAccessController{}, "Get:GetQrcodeForLogin")
web.Router("/auth/profile", &controllers.LoginAccessController{}, "Get:LoginInfoByAuthCode")
web.Router("/common/dictionary/search", &common_controller.CommonController{}, "Post:GetDictionaryByCode")
}
... ...