作者 tangxuhui

更新

正在显示 24 个修改的文件 包含 236 行增加324 行删除
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type GetQrcodeForLoginQuery struct {
}
func (getQrcodeForLoginQuery *GetQrcodeForLoginQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getQrcodeForLoginQuery *GetQrcodeForLoginQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getQrcodeForLoginQuery)
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 LoginByAccountQuery struct {
// 账号
Account string `json:"account,omitempty"`
// 密码
Passwd string `json:"passwd,omitempty"`
}
func (loginByAccountQuery *LoginByAccountQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (loginByAccountQuery *LoginByAccountQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(loginByAccountQuery)
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 LoginByScanQrcodeQuery struct {
// 登录认证的凭证
AuthCode string `json:"authCode,omitempty"`
}
func (loginByScanQrcodeQuery *LoginByScanQrcodeQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (loginByScanQrcodeQuery *LoginByScanQrcodeQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(loginByScanQrcodeQuery)
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 LoginBySmsCodeQuery struct {
// 手机号
Phone string `json:"phone,omitempty"`
// 短信验证码
SmsCode string `json:"smsCode,omitempty"`
}
func (loginBySmsCodeQuery *LoginBySmsCodeQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (loginBySmsCodeQuery *LoginBySmsCodeQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(loginBySmsCodeQuery)
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 LoginInfoByAuthCodeQuery struct {
// 登录认证的凭证
AuthCode string `json:"authCode,omitempty"`
// 公司id
CompanyId string `json:"companyId,omitempty"`
// 组织id
OrganizationId string `json:"organizationId,omitempty"`
}
func (loginInfoByAuthCodeQuery *LoginInfoByAuthCodeQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (loginInfoByAuthCodeQuery *LoginInfoByAuthCodeQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(loginInfoByAuthCodeQuery)
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 (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/loginAccess/query"
)
// 登录访问
type LoginAccessService struct {
}
// 获取扫码登录用的二维码信息
func (loginAccessService *LoginAccessService) GetQrcodeForLogin(getQrcodeForLoginQuery *query.GetQrcodeForLoginQuery) (interface{}, error) {
if err := getQrcodeForLoginQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 使用手机号和密码登录系统
func (loginAccessService *LoginAccessService) LoginByAccount(loginByAccountQuery *query.LoginByAccountQuery) (interface{}, error) {
if err := loginByAccountQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 询问扫二维码方式登录的状态
func (loginAccessService *LoginAccessService) LoginByScanQrcode(loginByScanQrcodeQuery *query.LoginByScanQrcodeQuery) (interface{}, error) {
if err := loginByScanQrcodeQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 使用手机号和短信验证码登录系统
func (loginAccessService *LoginAccessService) LoginBySmsCode(loginBySmsCodeQuery *query.LoginBySmsCodeQuery) (interface{}, error) {
if err := loginBySmsCodeQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 获取具体的进入系统的凭证
func (loginAccessService *LoginAccessService) LoginInfoByAuthCode(loginInfoByAuthCodeQuery *query.LoginInfoByAuthCodeQuery) (interface{}, error) {
if err := loginInfoByAuthCodeQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
func NewLoginAccessService(options map[string]interface{}) *LoginAccessService {
newLoginAccessService := &LoginAccessService{}
return newLoginAccessService
}
package query
type GetAccessTokenCommand struct {
AuthCode string `json:"authCode"`
}
func (cmd GetAccessTokenCommand) Valid() error {
return nil
}
... ... @@ -4,18 +4,21 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type CompanyUserUpdateCommand struct {
UsersId int64 `json:"usersId" valid:"Required"`
//操作人
Operator domain.Operator `json:"-"`
UsersId string `json:"usersId" valid:"Required"`
// 用户编号
UsersCode string `json:"usersCode,omitempty"`
// 用户名称
UsersName string `json:"usersName,omitempty"`
// 组织机构id
OrganizationId int64 `json:"organizationId,omitempty"`
OrganizationId string `json:"organizationId,omitempty"`
// 部门id
DepartmentId int64 `json:"departmentId,omitempty"`
DepartmentId string `json:"departmentId,omitempty"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `json:"enableStatus,omitempty"`
// 手机号
... ... @@ -23,9 +26,9 @@ type CompanyUserUpdateCommand struct {
// 邮箱
Email string `json:"email,omitempty"`
// 关联的组织机构
UsersOrg []int64 `json:"usersOrg,omitempty"`
UsersOrg []string `json:"usersOrg,omitempty"`
// 关联的组织结构
UsersRole []int64 `json:"usersRole,omitempty"`
UsersRole []string `json:"usersRole,omitempty"`
// 头像
Avator string `json:"avator,omitempty"`
}
... ...
... ... @@ -5,9 +5,9 @@ import (
"time"
"github.com/linmadan/egglib-go/core/application"
"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/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/users/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/users/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/users/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
... ... @@ -29,15 +29,20 @@ func (usersService *UsersService) CompanyUserGet(companyUserGetQuery *query.Comp
if err != nil {
return nil, err
}
//TODO 数据拼接
userInfo := domain.Users{
UserId: "",
user := domain.Users{
UserId: strconv.FormatInt(result.UserId, 10),
UserInfo: result.GetUserBase(),
Org: result.GetOrg(),
Department: result.GetDepartment(),
Company: nil,
UserOrg: result.GetUserOrg(),
UserRole: result.GetUserRole(),
}
return userInfo, err
datas := map[string]interface{}{
"user": user,
"userMenu": "",
}
return datas, err
}
// 创建公司用户信息
... ... @@ -148,8 +153,42 @@ func (usersService *UsersService) CompanyUserResetPassword(companyUserResetPassw
// 更新公司用户信息
func (usersService *UsersService) CompanyUserUpdate(companyUserUpdateCommand *command.CompanyUserUpdateCommand) (interface{}, error) {
return nil, nil
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
companyUserUpdateCommand.Operator.CompanyId,
companyUserUpdateCommand.Operator.OrgId,
companyUserUpdateCommand.Operator.UserId)
departmentId, _ := strconv.Atoi(companyUserUpdateCommand.OrganizationId)
orgId, _ := strconv.Atoi(companyUserUpdateCommand.OrganizationId)
userOrg := []int64{}
userRole := []int64{}
for _, v := range companyUserUpdateCommand.UsersOrg {
id, err := strconv.Atoi(v)
if err == nil {
userOrg = append(userOrg, int64(id))
}
}
for _, v := range companyUserUpdateCommand.UsersRole {
id, err := strconv.Atoi(v)
if err == nil {
userRole = append(userRole, int64(id))
}
}
userId, _ := strconv.Atoi(companyUserUpdateCommand.UsersId)
result, err := creationUserGateway.UserUpdate(allied_creation_user.ReqUpdateUser{
UserId: int64(userId),
CompanyId: companyUserUpdateCommand.Operator.CompanyId,
UserCode: companyUserUpdateCommand.UsersCode,
OrganizationId: int64(orgId),
DepartmentId: int64(departmentId),
UserOrg: userOrg,
UserRole: userRole,
EnableStatus: companyUserUpdateCommand.EnableStatus,
UserName: companyUserUpdateCommand.UsersName,
Phone: companyUserUpdateCommand.Phone,
Avatar: companyUserUpdateCommand.Avator,
Email: companyUserUpdateCommand.Avator,
})
return result, err
}
// 创建共创用户信息
... ...
... ... @@ -45,14 +45,14 @@ type UserDetail struct {
DepartmentName string `json:"departmentName"`
} `json:"department,omitempty"`
UserRole []struct {
RoleID int `json:"roleId"`
RoleID int64 `json:"roleId"`
RoleName string `json:"roleName"`
Ext struct {
OrgName string `json:"orgName"`
} `json:"ext,omitempty"`
} `json:"userRole"`
UserOrg []struct {
OrgID int `json:"orgId"`
OrgID int64 `json:"orgId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
... ... @@ -62,24 +62,16 @@ type UserDetail struct {
func (info *UserDetail) GetUserBase() *domain.UsersBase {
return &domain.UsersBase{
UserId: strconv.Itoa(int(info.UserId)),
UserBaseId: strconv.Itoa(int(info.UserBaseId)),
UserType: info.UserType,
// 用户状态,1启用,2禁用
EnableStatus: info.EnableStatus,
// 手机号码
Phone: info.UserInfo.Phone,
// 用户编号
UserCode: info.UserCode,
// 用户姓名
UserName: info.UserInfo.UserName,
// 邮箱
Email: info.UserInfo.Email,
//头像
Avatar: info.UserInfo.Avatar,
// 共创公司
CooperationCompany: info.CooperationInfo.CooperationCompany,
// 共创公司到期时间
UserId: strconv.Itoa(int(info.UserId)),
UserBaseId: strconv.Itoa(int(info.UserBaseId)),
UserType: info.UserType,
EnableStatus: info.EnableStatus,
Phone: info.UserInfo.Phone,
UserCode: info.UserCode,
UserName: info.UserInfo.UserName,
Email: info.UserInfo.Email,
Avatar: info.UserInfo.Avatar,
CooperationCompany: info.CooperationInfo.CooperationCompany,
CooperationDeadline: info.CooperationInfo.CooperationDeadline,
}
}
... ... @@ -125,6 +117,42 @@ func (info *UserDetail) GetOrg() *domain.Orgs {
}
}
func (info *UserDetail) GetUserOrg() []domain.Orgs {
var (
userOrgs []domain.Orgs
userOrg domain.Orgs
)
for _, v := range info.UserOrg {
userOrg = domain.Orgs{
OrgId: strconv.FormatInt(v.OrgID, 10),
OrgName: v.OrgName,
OrgCode: "",
ParentId: 0,
}
userOrgs = append(userOrgs, userOrg)
}
return userOrgs
}
func (info *UserDetail) GetUserRole() []domain.Roles {
var (
roles []domain.Roles
role domain.Roles
)
for _, v := range info.UserRole {
role = domain.Roles{
RoleId: strconv.FormatInt(v.RoleID, 10),
RoleName: v.RoleName,
// 用户的组织
Org: &domain.Orgs{
OrgName: v.RoleName,
},
}
roles = append(roles, role)
}
return roles
}
//搜索用户列表
type (
ReqUserSearch struct {
... ... @@ -195,10 +223,9 @@ type (
//更新用户
type (
ReqUpdateUser struct {
UserId int64
// 企业id
CompanyId int64 `json:"companyId"`
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType int `json:"userType"`
// 用户编号 企业内标识
UserCode string ` json:"userCode" `
// 组织机构
... ... @@ -215,8 +242,6 @@ type (
CooperationDeadline time.Time ` json:"cooperationDeadline,omitempty"`
// 启用状态(启用:1 禁用:2)
EnableStatus int ` json:"enableStatus,omitempty"`
// 密码
Password string ` json:"password" `
// 用户姓名
UserName string `json:"userName"`
// 手机号码
... ...
package web_client
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/users/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/users/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/users/service"
)
type UsersController struct {
beego.BaseController
}
func (controller *UsersController) CompanyUserAdd() {
usersService := service.NewUsersService(nil)
companyUserAddCommand := &command.CompanyUserAddCommand{}
controller.Unmarshal(companyUserAddCommand)
data, err := usersService.CompanyUserAdd(companyUserAddCommand)
controller.Response(data, err)
}
func (controller *UsersController) CompanyUserUpdate() {
usersService := service.NewUsersService(nil)
companyUserUpdateCommand := &command.CompanyUserUpdateCommand{}
controller.Unmarshal(companyUserUpdateCommand)
data, err := usersService.CompanyUserUpdate(companyUserUpdateCommand)
controller.Response(data, err)
}
func (controller *UsersController) CompanyUserList() {
usersService := service.NewUsersService(nil)
companyUserListQuery := &query.CompanyUserListQuery{}
cnt, data, err := usersService.CompanyUserList(companyUserListQuery)
_ = cnt
controller.Response(data, err)
}
func (controller *UsersController) CompanyUserGet() {
usersService := service.NewUsersService(nil)
companyUserGetQuery := &query.CompanyUserGetQuery{}
userId, _ := controller.GetInt64(":userId")
companyUserGetQuery.UsersId = userId
data, err := usersService.CompanyUserGet(companyUserGetQuery)
controller.Response(data, err)
}
func (controller *UsersController) CompanyUserEnable() {
usersService := service.NewUsersService(nil)
companyUserEnableCommand := &command.CompanyUserEnableCommand{}
controller.Unmarshal(companyUserEnableCommand)
data, err := usersService.CompanyUserEnable(companyUserEnableCommand)
controller.Response(data, err)
}
func (controller *UsersController) CompanyUserResetPassword() {
usersService := service.NewUsersService(nil)
companyUserResetPasswordCommand := &command.CompanyUserResetPasswordCommand{}
controller.Unmarshal(companyUserResetPasswordCommand)
data, err := usersService.CompanyUserResetPassword(companyUserResetPasswordCommand)
controller.Response(data, err)
}
func (controller *UsersController) CooperationUserAdd() {
usersService := service.NewUsersService(nil)
cooperationUserAddCommand := &command.CooperationUserAddCommand{}
controller.Unmarshal(cooperationUserAddCommand)
data, err := usersService.CooperationUserAdd(cooperationUserAddCommand)
controller.Response(data, err)
}
func (controller *UsersController) CooperationUserUpdate() {
usersService := service.NewUsersService(nil)
cooperationUserUpdateCommand := &command.CooperationUserUpdateCommand{}
controller.Unmarshal(cooperationUserUpdateCommand)
data, err := usersService.CooperationUserUpdate(cooperationUserUpdateCommand)
controller.Response(data, err)
}
func (controller *UsersController) CooperationUserList() {
usersService := service.NewUsersService(nil)
cooperationUserListQuery := &query.CooperationUserListQuery{}
cnt, data, err := usersService.CooperationUserList(cooperationUserListQuery)
_ = cnt
controller.Response(data, err)
}
func (controller *UsersController) CooperationUserGet() {
usersService := service.NewUsersService(nil)
cooperationUserGetQuery := &query.CooperationUserGetQuery{}
userId, _ := controller.GetInt64(":userId")
cooperationUserGetQuery.UsersId = userId
data, err := usersService.CooperationUserGet(cooperationUserGetQuery)
controller.Response(data, err)
}
func (controller *UsersController) CooperationUserEnable() {
usersService := service.NewUsersService(nil)
cooperationUserEnableCommand := &command.CooperationUserEnableCommand{}
controller.Unmarshal(cooperationUserEnableCommand)
data, err := usersService.CooperationUserEnable(cooperationUserEnableCommand)
controller.Response(data, err)
}
func (controller *UsersController) CooperationUserResetPassword() {
usersService := service.NewUsersService(nil)
cooperationUserResetPasswordCommand := &command.CooperationUserResetPasswordCommand{}
controller.Unmarshal(cooperationUserResetPasswordCommand)
data, err := usersService.CooperationUserResetPassword(cooperationUserResetPasswordCommand)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
)
func init() {
web.Router("/v1/web/users/company-user", &web_client.UsersController{}, "Post:CompanyUserAdd")
web.Router("/v1/web/users/company-user", &web_client.UsersController{}, "Put:CompanyUserUpdate")
web.Router("/v1/web/users/company-user/search", &web_client.UsersController{}, "Post:CompanyUserList")
web.Router("/v1/web/users/company-user/:userId", &web_client.UsersController{}, "Get:CompanyUserGet")
web.Router("/v1/web/users/company-user/enable", &web_client.UsersController{}, "Put:CompanyUserEnable")
web.Router("/v1/web/users/company-user/reset-password", &web_client.UsersController{}, "Put:CompanyUserResetPassword")
web.Router("/v1/web/users/cooperation-user", &web_client.UsersController{}, "Post:CooperationUserAdd")
web.Router("/v1/web/users/cooperation-user", &web_client.UsersController{}, "Put:CooperationUserUpdate")
web.Router("/v1/web/users/cooperation-user/search", &web_client.UsersController{}, "Post:CooperationUserList")
web.Router("/v1/web/users/cooperation-user/:userId", &web_client.UsersController{}, "Get:CooperationUserGet")
web.Router("/v1/web/users/cooperation-user/enable", &web_client.UsersController{}, "Put:CooperationUserEnable")
web.Router("/v1/web/users/cooperation-user/reset-password", &web_client.UsersController{}, "Put:CooperationUserResetPassword")
}
... ...