作者 yangfu

add user

正在显示 33 个修改的文件 包含 1991 行增加0 行删除
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type BatchAddCommand struct {
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType int `cname:"用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)" json:"userType" valid:"Required"`
// 用户列表
User []*domain.User `cname:"用户列表" json:"user,omitempty"`
// 密码
Password string `cname:"密码" json:"password" valid:"Required"`
}
func (batchAddCommand *BatchAddCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchAddCommand *BatchAddCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchAddCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchAddCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type BatchEnableCommand struct {
UserIds []int64 `cname:"" json:"userIds" valid:"Required"`
// 启用状态(启用:1 禁用:2 注销:3)
EnableStatus int `cname:"启用状态(启用:1 禁用:2 注销:3)" json:"enableStatus" valid:"Required"`
}
func (batchEnableCommand *BatchEnableCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchEnableCommand *BatchEnableCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchEnableCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchEnableCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type BatchResetPasswordCommand struct {
UserIds []int64 `cname:"" json:"userIds" valid:"Required"`
// 密码
Password string `cname:"密码" json:"password" valid:"Required"`
}
func (batchResetPasswordCommand *BatchResetPasswordCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (batchResetPasswordCommand *BatchResetPasswordCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(batchResetPasswordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(batchResetPasswordCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateCooperatorCommand struct {
// 共创公司
CooperationCompany string `cname:"共创公司" json:"cooperationCompany" valid:"Required"`
// 共创到期时间
CooperationDeadline time.Time `cname:"共创到期时间" json:"cooperationDeadline" valid:"Required"`
// 邮箱
Email string `cname:"邮箱" json:"email" valid:"Required"`
// 启用状态(启用:1 禁用:2 注销:3)
EnableStatus int `cname:"启用状态(启用:1 禁用:2 注销:3)" json:"enableStatus" valid:"Required"`
// 用户编号 企业内标识
UserCode string `cname:"用户编号 企业内标识" json:"userCode" valid:"Required"`
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 组织ID
OrgId int64 `cname:"组织ID" json:"orgId,string" valid:"Required"`
}
func (createCooperatorCommand *CreateCooperatorCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCooperatorCommand *CreateCooperatorCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCooperatorCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createCooperatorCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateUserCommand struct {
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType int `cname:"用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)" json:"userType" valid:"Required"`
// 用户编号 企业内标识
UserCode string `cname:"用户编号 企业内标识" json:"userCode" valid:"Required"`
// 组织机构
OrganizationId int64 `cname:"组织机构" json:"organizationId,string,omitempty"`
// 所属部门
DepartmentId int64 `cname:"所属部门" json:"departmentId,string,omitempty"`
// 用户关联的组织
UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"`
// 用户关联的角色
UserRole []*domain.Role `cname:"用户关联的角色" json:"userRole,omitempty"`
// 共创公司
CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"`
// 共创到期时间 (yyyy-MM-dd)
CooperationDeadline time.Time `cname:"共创到期时间 (yyyy-MM-dd)" json:"cooperationDeadline,omitempty"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `cname:"启用状态(启用:1 禁用:2)" json:"enableStatus,omitempty"`
// 密码
Password string `cname:"密码" json:"password" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 邮箱
Email string `cname:"邮箱" json:"email" valid:"Required"`
}
func (createUserCommand *CreateUserCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createUserCommand *CreateUserCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createUserCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createUserCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type DeleteFavoriteMenusCommand struct {
// 编码
Code int `cname:"编码" json:"code" valid:"Required"`
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
}
func (deleteFavoriteMenusCommand *DeleteFavoriteMenusCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (deleteFavoriteMenusCommand *DeleteFavoriteMenusCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(deleteFavoriteMenusCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(deleteFavoriteMenusCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveUserCommand struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
}
func (removeUserCommand *RemoveUserCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeUserCommand *RemoveUserCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeUserCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeUserCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type UpdateCooperatorCommand struct {
// 共创公司
CooperationCompany string `cname:"共创公司" json:"cooperationCompany" valid:"Required"`
// 共创到期时间
CooperationDeadline time.Time `cname:"共创到期时间" json:"cooperationDeadline" valid:"Required"`
// 邮箱
Email string `cname:"邮箱" json:"email" valid:"Required"`
// 启用状态(启用:1 禁用:2 注销:3)
EnableStatus int `cname:"启用状态(启用:1 禁用:2 注销:3)" json:"enableStatus" valid:"Required"`
// 用户编号 企业内标识
UserCode string `cname:"用户编号 企业内标识" json:"userCode" valid:"Required"`
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 组织ID
OrgId int64 `cname:"组织ID" json:"orgId,string" valid:"Required"`
}
func (updateCooperatorCommand *UpdateCooperatorCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCooperatorCommand *UpdateCooperatorCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCooperatorCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCooperatorCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateFavoriteMenusCommand struct {
// 菜单编码列表
FavoriteMenus []string `cname:"菜单编码列表" json:"favoriteMenus,omitempty"`
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
}
func (updateFavoriteMenusCommand *UpdateFavoriteMenusCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateFavoriteMenusCommand *UpdateFavoriteMenusCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateFavoriteMenusCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateFavoriteMenusCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type UpdateUserCommand struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
// 组织机构
OrganizationId int64 `cname:"组织机构" json:"organizationId,string,omitempty"`
// 所属部门
DepartmentId int64 `cname:"所属部门" json:"departmentId,string,omitempty"`
// 用户关联的组织
UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"`
// 用户关联的角色
UserRole []*domain.Role `cname:"用户关联的角色" json:"userRole,omitempty"`
// 共创公司
CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"`
// 共创到期时间 (yyyy-MM-dd)
CooperationDeadline time.Time `cname:"共创到期时间 (yyyy-MM-dd)" json:"cooperationDeadline,omitempty"`
// 启用状态(启用:1 禁用:2)
EnableStatus int `cname:"启用状态(启用:1 禁用:2)" json:"enableStatus,omitempty"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 邮箱
Email string `cname:"邮箱" json:"email" valid:"Required"`
}
func (updateUserCommand *UpdateUserCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateUserCommand *UpdateUserCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateUserCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateUserCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateUsersBaseCommand struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 头像
Avatar string `cname:"头像" json:"avatar" valid:"Required"`
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 邮箱
Email string `cname:"邮箱" json:"email" valid:"Required"`
}
func (updateUsersBaseCommand *UpdateUsersBaseCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateUsersBaseCommand *UpdateUsersBaseCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateUsersBaseCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateUsersBaseCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetFavoriteMenusQuery struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
}
func (getFavoriteMenusQuery *GetFavoriteMenusQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getFavoriteMenusQuery *GetFavoriteMenusQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getFavoriteMenusQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getFavoriteMenusQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetUserQuery struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
}
func (getUserQuery *GetUserQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getUserQuery *GetUserQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getUserQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getUserQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetUserAccessMenusQuery struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
// 菜单类别 web app
MenuCategory string `cname:"菜单类别 web app" json:"menuCategory,omitempty"`
}
func (getUserAccessMenusQuery *GetUserAccessMenusQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getUserAccessMenusQuery *GetUserAccessMenusQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getUserAccessMenusQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getUserAccessMenusQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetUserProfileQuery struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string,omitempty"`
// 手机号码
Phone string `cname:"手机号码" json:"phone,omitempty"`
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId,string,omitempty"`
// 用户编号 企业内标识
UserCode string `cname:"用户编号 企业内标识" json:"userCode,omitempty"`
}
func (getUserProfileQuery *GetUserProfileQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getUserProfileQuery *GetUserProfileQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getUserProfileQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getUserProfileQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListUserQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId,string,omitempty"`
// 组织ID
OrganizationId int64 `cname:"组织ID" json:"organizationId,string,omitempty"`
// 部门编号
DepartmentId int64 `cname:"部门编号" json:"departmentId,string,omitempty"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName,omitempty"`
// 部门名称
DepName string `cname:"部门名称" json:"depName,omitempty"`
// 手机号码
Phone string `cname:"手机号码" json:"phone,omitempty"`
}
func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listUserQuery *ListUserQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listUserQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listUserQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
)
// 用户
type UserService struct {
}
// 批量添加
func (userService *UserService) BatchAdd(batchAddCommand *command.BatchAddCommand) (interface{}, error) {
if err := batchAddCommand.ValidateCommand(); 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 (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEnableCommand) (interface{}, error) {
if err := batchEnableCommand.ValidateCommand(); 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 (userService *UserService) BatchResetPassword(batchResetPasswordCommand *command.BatchResetPasswordCommand) (interface{}, error) {
if err := batchResetPasswordCommand.ValidateCommand(); 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 (userService *UserService) CreateCooperator(createCooperatorCommand *command.CreateCooperatorCommand) (interface{}, error) {
if err := createCooperatorCommand.ValidateCommand(); 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 (userService *UserService) CreateUser(createUserCommand *command.CreateUserCommand) (interface{}, error) {
if err := createUserCommand.ValidateCommand(); 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()
}()
newUser := &domain.User{
CompanyId: createUserCommand.CompanyId,
UserType: createUserCommand.UserType,
UserCode: createUserCommand.UserCode,
OrganizationId: createUserCommand.OrganizationId,
DepartmentId: createUserCommand.DepartmentId,
UserOrg: createUserCommand.UserOrg,
UserRole: createUserCommand.UserRole,
//CooperationInfo: createUserCommand.CooperationInfo,
EnableStatus: createUserCommand.EnableStatus,
//Password: createUserCommand.Password,
//UserName: createUserCommand.UserName,
//Phone: createUserCommand.Phone,
//Avatar: createUserCommand.Avatar,
//Email: createUserCommand.Email,
}
var userRepository domain.UserRepository
if value, err := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
userRepository = value
}
if user, err := userRepository.Save(newUser); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
}
}
// 移除我收藏的菜单
func (userService *UserService) DeleteFavoriteMenus(deleteFavoriteMenusCommand *command.DeleteFavoriteMenusCommand) (interface{}, error) {
if err := deleteFavoriteMenusCommand.ValidateCommand(); 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 (userService *UserService) GetFavoriteMenus(getFavoriteMenusQuery *query.GetFavoriteMenusQuery) (interface{}, error) {
if err := getFavoriteMenusQuery.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 (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (interface{}, error) {
if err := getUserQuery.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()
}()
var userRepository domain.UserRepository
if value, err := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
userRepository = value
}
user, err := userRepository.FindOne(map[string]interface{}{"userId": getUserQuery.UserId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if user == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getUserQuery.UserId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
}
}
// 返回用户有权限的菜单
func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *query.GetUserAccessMenusQuery) (interface{}, error) {
if err := getUserAccessMenusQuery.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 (userService *UserService) GetUserProfile(getUserProfileQuery *query.GetUserProfileQuery) (interface{}, error) {
if err := getUserProfileQuery.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 (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (interface{}, error) {
if err := listUserQuery.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()
}()
var userRepository domain.UserRepository
if value, err := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
userRepository = value
}
if count, users, err := userRepository.Find(tool_funs.SimpleStructToMap(listUserQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"users": users,
}, nil
}
}
// 移除
func (userService *UserService) RemoveUser(removeUserCommand *command.RemoveUserCommand) (interface{}, error) {
if err := removeUserCommand.ValidateCommand(); 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()
}()
var userRepository domain.UserRepository
if value, err := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
userRepository = value
}
user, err := userRepository.FindOne(map[string]interface{}{"userId": removeUserCommand.UserId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if user == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeUserCommand.UserId)))
}
if user, err := userRepository.Remove(user); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
}
}
// 更新共创用户
func (userService *UserService) UpdateCooperator(updateCooperatorCommand *command.UpdateCooperatorCommand) (interface{}, error) {
if err := updateCooperatorCommand.ValidateCommand(); 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 (userService *UserService) UpdateFavoriteMenus(updateFavoriteMenusCommand *command.UpdateFavoriteMenusCommand) (interface{}, error) {
if err := updateFavoriteMenusCommand.ValidateCommand(); 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 (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUserCommand) (interface{}, error) {
if err := updateUserCommand.ValidateCommand(); 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()
}()
var userRepository domain.UserRepository
if value, err := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
userRepository = value
}
user, err := userRepository.FindOne(map[string]interface{}{"userId": updateUserCommand.UserId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if user == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateUserCommand.UserId)))
}
if err := user.Update(tool_funs.SimpleStructToMap(updateUserCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if user, err := userRepository.Save(user); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return user, nil
}
}
// 更新用户基础信息数据
func (userService *UserService) UpdateUsersBase(updateUsersBaseCommand *command.UpdateUsersBaseCommand) (interface{}, error) {
if err := updateUsersBaseCommand.ValidateCommand(); 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 NewUserService(options map[string]interface{}) *UserService {
newUserService := &UserService{}
return newUserService
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/service"
)
type UserController struct {
beego.BaseController
}
func (controller *UserController) CreateUser() {
userService := service.NewUserService(nil)
createUserCommand := &command.CreateUserCommand{}
controller.Unmarshal(createUserCommand)
data, err := userService.CreateUser(createUserCommand)
controller.Response(data, err)
}
func (controller *UserController) UpdateUser() {
userService := service.NewUserService(nil)
updateUserCommand := &command.UpdateUserCommand{}
controller.Unmarshal(updateUserCommand)
userId, _ := controller.GetInt64(":userId")
updateUserCommand.UserId = userId
data, err := userService.UpdateUser(updateUserCommand)
controller.Response(data, err)
}
func (controller *UserController) GetUser() {
userService := service.NewUserService(nil)
getUserQuery := &query.GetUserQuery{}
userId, _ := controller.GetInt64(":userId")
getUserQuery.UserId = userId
data, err := userService.GetUser(getUserQuery)
controller.Response(data, err)
}
func (controller *UserController) RemoveUser() {
userService := service.NewUserService(nil)
removeUserCommand := &command.RemoveUserCommand{}
controller.Unmarshal(removeUserCommand)
userId, _ := controller.GetInt64(":userId")
removeUserCommand.UserId = userId
data, err := userService.RemoveUser(removeUserCommand)
controller.Response(data, err)
}
func (controller *UserController) ListUser() {
userService := service.NewUserService(nil)
listUserQuery := &query.ListUserQuery{}
data, err := userService.ListUser(listUserQuery)
controller.Response(data, err)
}
func (controller *UserController) GetUserAccessMenus() {
userService := service.NewUserService(nil)
getUserAccessMenusQuery := &query.GetUserAccessMenusQuery{}
userId, _ := controller.GetInt64(":userId")
getUserAccessMenusQuery.UserId = userId
menuCategory := controller.GetString("menuCategory")
getUserAccessMenusQuery.MenuCategory = menuCategory
data, err := userService.GetUserAccessMenus(getUserAccessMenusQuery)
controller.Response(data, err)
}
func (controller *UserController) GetUserProfile() {
userService := service.NewUserService(nil)
getUserProfileQuery := &query.GetUserProfileQuery{}
userId, _ := controller.GetInt64(":userId")
getUserProfileQuery.UserId = userId
data, err := userService.GetUserProfile(getUserProfileQuery)
controller.Response(data, err)
}
func (controller *UserController) BatchAdd() {
userService := service.NewUserService(nil)
batchAddCommand := &command.BatchAddCommand{}
controller.Unmarshal(batchAddCommand)
data, err := userService.BatchAdd(batchAddCommand)
controller.Response(data, err)
}
func (controller *UserController) BatchEnable() {
userService := service.NewUserService(nil)
batchEnableCommand := &command.BatchEnableCommand{}
controller.Unmarshal(batchEnableCommand)
data, err := userService.BatchEnable(batchEnableCommand)
controller.Response(data, err)
}
func (controller *UserController) BatchResetPassword() {
userService := service.NewUserService(nil)
batchResetPasswordCommand := &command.BatchResetPasswordCommand{}
controller.Unmarshal(batchResetPasswordCommand)
data, err := userService.BatchResetPassword(batchResetPasswordCommand)
controller.Response(data, err)
}
func (controller *UserController) UpdateUsersBase() {
userService := service.NewUserService(nil)
updateUsersBaseCommand := &command.UpdateUsersBaseCommand{}
controller.Unmarshal(updateUsersBaseCommand)
userId, _ := controller.GetInt64(":userId")
updateUsersBaseCommand.UserId = userId
data, err := userService.UpdateUsersBase(updateUsersBaseCommand)
controller.Response(data, err)
}
func (controller *UserController) CreateCooperator() {
userService := service.NewUserService(nil)
createCooperatorCommand := &command.CreateCooperatorCommand{}
controller.Unmarshal(createCooperatorCommand)
data, err := userService.CreateCooperator(createCooperatorCommand)
controller.Response(data, err)
}
func (controller *UserController) UpdateCooperator() {
userService := service.NewUserService(nil)
updateCooperatorCommand := &command.UpdateCooperatorCommand{}
controller.Unmarshal(updateCooperatorCommand)
userId, _ := controller.GetInt64(":userId")
updateCooperatorCommand.UserId = userId
data, err := userService.UpdateCooperator(updateCooperatorCommand)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego/controllers"
)
func init() {
web.Router("/user/", &controllers.UserController{}, "Post:CreateUser")
web.Router("/user/:userId", &controllers.UserController{}, "Put:UpdateUser")
web.Router("/user/:userId", &controllers.UserController{}, "Get:GetUser")
web.Router("/user/:userId", &controllers.UserController{}, "Delete:RemoveUser")
web.Router("/user/search", &controllers.UserController{}, "Post:ListUser")
web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus")
web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile")
web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd")
web.Router("/user/batch-enable", &controllers.UserController{}, "Post:BatchEnable")
web.Router("/user/batch-reset-password", &controllers.UserController{}, "Post:BatchResetPassword")
web.Router("/user/:userId/base-info", &controllers.UserController{}, "Put:UpdateUsersBase")
web.Router("/user/cooperator", &controllers.UserController{}, "Post:CreateCooperator")
web.Router("/user/cooperator/:userId", &controllers.UserController{}, "Put:UpdateCooperator")
}
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("批量添加", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("批量添加", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"userType": "int",
"user": "array",
"password": "string",
}
httpExpect.POST("/user/batch-add").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("批量修改启用状态", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("批量修改启用状态", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"userIds": "array",
"enableStatus": "int",
}
httpExpect.POST("/user/batch-enable").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("批量重置密码", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("批量重置密码", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"userIds": "array",
"password": "string",
}
httpExpect.POST("/user/batch-reset-password").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("创建共创用户", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("创建共创用户", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationCompany": "string",
"cooperationDeadline": "datetime",
"email": "string",
"enableStatus": "int",
"userCode": "string",
"userId": "int64",
"userName": "string",
"avatar": "string",
"orgId": "int64",
}
httpExpect.POST("/user/cooperator").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("创建", func() {
Describe("提交数据创建", func() {
Context("提交正确的新用户数据", func() {
It("返回用户数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": "int64",
"userType": "int",
"userCode": "string",
"organizationId": "int64",
"departmentId": "int64",
"userOrg": "array",
"userRole": "array",
"cooperationCompany": "string",
"cooperationDeadline": "datetime",
"enableStatus": "int",
"password": "string",
"userName": "string",
"phone": "string",
"avatar": "string",
"email": "string",
}
httpExpect.POST("/user/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("userId").ValueNotEqual("userId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("返回用户有权限的菜单", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("返回用户有权限的菜单", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/user/{userId}/access-menus").
WithQuery("menuCategory", "string").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("获取用户概要数据", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("获取用户概要数据", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/user/{userId}/profile").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("返回", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据userId参数返回用户", func() {
Context("传入有效的userId", func() {
It("返回用户数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/user/{userId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("返回列表", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回用户列表", func() {
Context("传入有效的参数", func() {
It("返回用户数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"offset": "int",
"limit": "int",
"companyId": "int64",
"organizationId": "int64",
"departmentId": "int64",
"userName": "string",
"depName": "string",
"phone": "string",
}
httpExpect.POST("/user/search").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("users").Value("users").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("移除", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除", func() {
Context("传入有效的userId", func() {
It("返回被移除用户的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/user/{userId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("更新共创用户", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("更新共创用户", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationCompany": "string",
"cooperationDeadline": "datetime",
"email": "string",
"enableStatus": "int",
"userCode": "string",
"userName": "string",
"avatar": "string",
"orgId": "int64",
}
httpExpect.PUT("/user/cooperator/{userId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("更新", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新", func() {
Context("提交正确的用户数据", func() {
It("返回更新后的用户数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"organizationId": "int64",
"departmentId": "int64",
"userOrg": "array",
"userRole": "array",
"cooperationCompany": "string",
"cooperationDeadline": "datetime",
"enableStatus": "int",
"userName": "string",
"phone": "string",
"avatar": "string",
"email": "string",
}
httpExpect.PUT("/user/{userId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("userId").ValueEqual("userId", userId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
)
var _ = Describe("更新用户基础信息数据", func() {
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("更新用户基础信息数据", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"userName": "string",
"avatar": "string",
"phone": "string",
"email": "string",
}
httpExpect.PUT("/user/{userId}/base-info").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package user
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/beego/beego/v2/server/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego"
)
func TestUser(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port User Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = web.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...