作者 yangfu

meger branch '8-api-m-auth-event' to 'dev'

add companyCreatedEvent/companyAdminAssignedEvent
@@ -22,4 +22,5 @@ _testmain.go @@ -22,4 +22,5 @@ _testmain.go
22 *.exe 22 *.exe
23 *.test 23 *.test
24 .log 24 .log
25 -.idea  
  25 +.idea
  26 +.tmp
1 -{"/Users/steve/go/src/partner01/pkg/port/beego":1617694648836700729}  
不能预览此文件类型
@@ -3,16 +3,21 @@ package service @@ -3,16 +3,21 @@ package service
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
  6 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 8 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/command" 9 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/command"
8 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/query" 10 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/query"
  11 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/event/subscriber"
9 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/factory" 12 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/factory"
10 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" 13 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  14 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain/event"
11 "time" 15 "time"
12 ) 16 )
13 17
14 // 公司服务 18 // 公司服务
15 type CompanyService struct { 19 type CompanyService struct {
  20 + coreDomain.BaseEventPublisher
16 } 21 }
17 22
18 // 公司状态转换 禁用、启用 23 // 公司状态转换 禁用、启用
@@ -86,7 +91,7 @@ func (companyService *CompanyService) CreateCompany(createCompanyCommand *comman @@ -86,7 +91,7 @@ func (companyService *CompanyService) CreateCompany(createCompanyCommand *comman
86 Admin: &domain.CompanyAdmin{ 91 Admin: &domain.CompanyAdmin{
87 UserAccount: createCompanyCommand.UserAccount, // 用户手机号 92 UserAccount: createCompanyCommand.UserAccount, // 用户手机号
88 UserName: createCompanyCommand.UserName, // 用户名称 93 UserName: createCompanyCommand.UserName, // 用户名称
89 - }, // 公司主管理员 94 + }, // 公司主管理员
90 }, 95 },
91 CreateAt: time.Now(), 96 CreateAt: time.Now(),
92 UpdateAt: time.Now(), 97 UpdateAt: time.Now(),
@@ -103,7 +108,10 @@ func (companyService *CompanyService) CreateCompany(createCompanyCommand *comman @@ -103,7 +108,10 @@ func (companyService *CompanyService) CreateCompany(createCompanyCommand *comman
103 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 108 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
104 } else { 109 } else {
105 // todo 新增公司管理员 110 // todo 新增公司管理员
106 - 111 + companyService.Subscribe(&subscriber.UsersServiceSubscriber{TransactionContext: transactionContext.(*pgTransaction.TransactionContext)})
  112 + companyService.Publish(&event.CompanyCreated{
  113 + Company: company,
  114 + })
107 if err := transactionContext.CommitTransaction(); err != nil { 115 if err := transactionContext.CommitTransaction(); err != nil {
108 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 116 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
109 } 117 }
@@ -178,7 +186,7 @@ func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCo @@ -178,7 +186,7 @@ func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCo
178 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 186 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
179 } 187 }
180 return map[string]interface{}{ 188 return map[string]interface{}{
181 - "count": count, 189 + "count": count,
182 "companies": companies, 190 "companies": companies,
183 }, nil 191 }, nil
184 } 192 }
@@ -268,7 +276,11 @@ func (companyService *CompanyService) SetCompanyAdmin(setCompanyAdminCommand *co @@ -268,7 +276,11 @@ func (companyService *CompanyService) SetCompanyAdmin(setCompanyAdminCommand *co
268 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 276 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
269 } else { 277 } else {
270 // todo 更改公司管理员 278 // todo 更改公司管理员
271 - 279 + companyService.Subscribe(&subscriber.UsersServiceSubscriber{TransactionContext: transactionContext.(*pgTransaction.TransactionContext)})
  280 + companyService.Publish(&event.CompanyAdminAssigned{
  281 + CompanyId: company.CompanyId,
  282 + Admin: company.CompanyInfo.Admin,
  283 + })
272 if err := transactionContext.CommitTransaction(); err != nil { 284 if err := transactionContext.CommitTransaction(); err != nil {
273 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 285 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
274 } 286 }
  1 +package subscriber
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/domain"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/factory"
  7 + domainx "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain/event"
  9 + "time"
  10 +)
  11 +
  12 +type UsersServiceSubscriber struct {
  13 + TransactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (subscriber *UsersServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
  17 + userCreateService, _ := factory.CreateUserCreateService(map[string]interface{}{
  18 + "transactionContext": subscriber.TransactionContext,
  19 + })
  20 + switch domainEvent.EventType() {
  21 + case event.CompanyCreatedEvent:
  22 + companyCreatedEvent := domainEvent.(*event.CompanyCreated)
  23 + admin := companyCreatedEvent.Company.CompanyInfo.Admin
  24 + if _, err := userCreateService.CreateUser(companyCreatedEvent.OperatorId, &domainx.User{
  25 + UserType: domainx.Manager,
  26 + CompanyId: companyCreatedEvent.Company.CompanyId,
  27 + UserInfo: &domainx.UserInfo{
  28 + IsPrincipal: true,
  29 + UserAccount: admin.UserAccount,
  30 + UserName: admin.UserName,
  31 + },
  32 + AdminType: domainx.EnterpriseAdministrator,
  33 + PartnerInfo: &domainx.PartnerInfo{},
  34 + Status: domainx.StatusEnable,
  35 + CreateAt: time.Now(),
  36 + }); err != nil {
  37 + return err
  38 + }
  39 + case event.CompanyAdminAssignedEvent:
  40 + companyAdminAssigned := domainEvent.(*event.CompanyAdminAssigned)
  41 + admin := companyAdminAssigned.Admin
  42 + if _, err := userCreateService.CreateUser(companyAdminAssigned.OperatorId, &domainx.User{
  43 + UserType: domainx.Manager,
  44 + CompanyId: companyAdminAssigned.CompanyId,
  45 + UserInfo: &domainx.UserInfo{
  46 + IsPrincipal: true,
  47 + UserAccount: admin.UserAccount,
  48 + UserName: admin.UserName,
  49 + },
  50 + AdminType: domainx.EnterpriseAdministrator,
  51 + PartnerInfo: &domainx.PartnerInfo{},
  52 + Status: domainx.StatusEnable,
  53 + CreateAt: time.Now(),
  54 + }); err != nil {
  55 + return err
  56 + }
  57 + case event.UsersCreatedEvent:
  58 +
  59 + }
  60 + return nil
  61 +}
  62 +
  63 +func (subscriber *UsersServiceSubscriber) SubscribedToEventTypes() []string {
  64 + return []string{
  65 + event.CompanyAdminAssignedEvent,
  66 + event.CompanyCreatedEvent,
  67 + }
  68 +}
@@ -37,3 +37,19 @@ func CreateReturnGoodsService(options map[string]interface{}) (service.ReturnGoo @@ -37,3 +37,19 @@ func CreateReturnGoodsService(options map[string]interface{}) (service.ReturnGoo
37 } 37 }
38 return domainService.NewReturnGoodsService(transactionContext) 38 return domainService.NewReturnGoodsService(transactionContext)
39 } 39 }
  40 +
  41 +func CreateUserCreateService(options map[string]interface{}) (service.UserCreateService, error) {
  42 + var transactionContext *pgTransaction.TransactionContext
  43 + if value, ok := options["transactionContext"]; ok {
  44 + transactionContext = value.(*pgTransaction.TransactionContext)
  45 + }
  46 + return domainService.NewUserCreateService(transactionContext)
  47 +}
  48 +
  49 +func CreatePhoneAuthService(options map[string]interface{}) (service.PhoneAuthService, error) {
  50 + var transactionContext *pgTransaction.TransactionContext
  51 + if value, ok := options["transactionContext"]; ok {
  52 + transactionContext = value.(*pgTransaction.TransactionContext)
  53 + }
  54 + return domainService.NewPhoneAuthenticationService(transactionContext)
  55 +}
@@ -4,7 +4,7 @@ import "os" @@ -4,7 +4,7 @@ import "os"
4 4
5 const SERVICE_NAME = "partner01" 5 const SERVICE_NAME = "partner01"
6 6
7 -var LOG_LEVEL = "debug" 7 +var LOG_LEVEL = "debug" //"debug"
8 8
9 func init() { 9 func init() {
10 if os.Getenv("LOG_LEVEL") != "" { 10 if os.Getenv("LOG_LEVEL") != "" {
  1 +package event
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  6 +)
  7 +
  8 +const CompanyAdminAssignedEvent = "Company-Admin-Assigned"
  9 +
  10 +type CompanyAdminAssigned struct {
  11 + coreDomain.BaseEvent
  12 + OperatorId int64
  13 + CompanyId int64
  14 + Admin *domain.CompanyAdmin
  15 +}
  16 +
  17 +func (event *CompanyAdminAssigned) EventType() string {
  18 + return CompanyAdminAssignedEvent
  19 +}
  1 +package event
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  6 +)
  7 +
  8 +const CompanyCreatedEvent = "Company-Created-Event"
  9 +
  10 +type CompanyCreated struct {
  11 + coreDomain.BaseEvent
  12 + OperatorId int64
  13 + Company *domain.Company
  14 +}
  15 +
  16 +func (event *CompanyCreated) EventType() string {
  17 + return CompanyCreatedEvent
  18 +}
  1 +package event
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  6 +)
  7 +
  8 +const UsersCreatedEvent = "Users-Created-Event"
  9 +
  10 +type UsersCreated struct {
  11 + coreDomain.BaseEvent
  12 + OperatorId int64
  13 + User *domain.User
  14 +}
  15 +
  16 +func (event *UsersCreated) EventType() string {
  17 + return UsersCreatedEvent
  18 +}
  1 +package service
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  6 +)
  7 +
  8 +type UserCreateService interface {
  9 + coreDomain.DomainEventPublisher
  10 + CreateUser(operatorId int64, user *domain.User) (*domain.User, error)
  11 +}
  1 +package service
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  6 +)
  7 +
  8 +type PhoneAuthService interface {
  9 + coreDomain.DomainEventPublisher
  10 + PhoneAuth(userId int64, phone, passwd string) (*domain.UserAuth, error)
  11 +}
@@ -36,23 +36,26 @@ func (userAuth *UserAuth) Identify() interface{} { @@ -36,23 +36,26 @@ func (userAuth *UserAuth) Identify() interface{} {
36 } 36 }
37 37
38 func (userAuth *UserAuth) Update(data map[string]interface{}) error { 38 func (userAuth *UserAuth) Update(data map[string]interface{}) error {
39 - if userAuthId, ok := data["userAuthId"]; ok {  
40 - userAuth.UserAuthId = userAuthId.(int64)  
41 - }  
42 if users, ok := data["users"]; ok { 39 if users, ok := data["users"]; ok {
43 userAuth.Users = users.([]int64) 40 userAuth.Users = users.([]int64)
44 } 41 }
45 if phone, ok := data["phone"]; ok { 42 if phone, ok := data["phone"]; ok {
46 userAuth.PhoneAuth.Phone = phone.(string) 43 userAuth.PhoneAuth.Phone = phone.(string)
47 } 44 }
48 - if password, ok := data["password"]; ok { 45 + if password, ok := data["password"]; ok && len(password.(string)) > 0 {
49 userAuth.PhoneAuth.Password = password.(string) 46 userAuth.PhoneAuth.Password = password.(string)
50 } 47 }
51 - if createAt, ok := data["createAt"]; ok {  
52 - userAuth.CreateAt = createAt.(time.Time)  
53 - }  
54 - if updateAt, ok := data["updateAt"]; ok {  
55 - userAuth.UpdateAt = updateAt.(time.Time) 48 + if uid, ok := data["userId"]; ok {
  49 + var userExisted bool = false
  50 + userId := uid.(int64)
  51 + for i := range userAuth.Users {
  52 + if userAuth.Users[i] == userId {
  53 + userExisted = true
  54 + }
  55 + }
  56 + if !userExisted {
  57 + userAuth.Users = append(userAuth.Users, userId)
  58 + }
56 } 59 }
57 return nil 60 return nil
58 } 61 }
  1 +package domainService
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg/v10"
  6 + "github.com/linmadan/egglib-go/core/application"
  7 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  8 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  9 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
  11 + "time"
  12 +)
  13 +
  14 +const defaultPassword = "7c4a8d09ca3762af61e59520943dc26494f8941b" //sha1 mmm123456
  15 +
  16 +type PhoneAuthenticationService struct {
  17 + coreDomain.BaseEventPublisher
  18 + transactionContext *pgTransaction.TransactionContext
  19 +}
  20 +
  21 +func (service *PhoneAuthenticationService) PhoneAuth(userId int64, phone, passwd string) (*domain.UserAuth, error) {
  22 + var userAuth *domain.UserAuth
  23 + var err error
  24 + UserAuthRepository, _ := repository.NewUserAuthRepository(service.transactionContext)
  25 + userAuth, err = UserAuthRepository.FindOne(map[string]interface{}{"phone": phone})
  26 + if userAuth != nil {
  27 + userAuth.Update(map[string]interface{}{"password": passwd, "userId": userId})
  28 + }
  29 + if err == pg.ErrNoRows {
  30 + if passwd == "" {
  31 + passwd = defaultPassword
  32 + }
  33 + userAuth = &domain.UserAuth{
  34 + Users: []int64{userId},
  35 + PhoneAuth: &domain.PhoneAuth{
  36 + Phone: phone,
  37 + Password: passwd,
  38 + },
  39 + CredentialAuths: []*domain.CredentialAuth{},
  40 + CreateAt: time.Now(),
  41 + UpdateAt: time.Now(),
  42 + }
  43 + err = nil
  44 + }
  45 + if err != nil {
  46 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  47 + }
  48 + return UserAuthRepository.Save(userAuth)
  49 +}
  50 +
  51 +func NewPhoneAuthenticationService(transactionContext *pgTransaction.TransactionContext) (*PhoneAuthenticationService, error) {
  52 + if transactionContext == nil {
  53 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  54 + } else {
  55 + return &PhoneAuthenticationService{
  56 + transactionContext: transactionContext,
  57 + }, nil
  58 + }
  59 +}
  1 +package domainService
  2 +
  3 +import (
  4 + "fmt"
  5 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
  9 +)
  10 +
  11 +type UserCreateService struct {
  12 + coreDomain.BaseEventPublisher
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (service *UserCreateService) CreateUser(operatorId int64, user *domain.User) (*domain.User, error) {
  17 + // 检查操作人权限
  18 + var err error
  19 + UserRepository, _ := repository.NewUserRepository(service.transactionContext)
  20 + //operator,err := UserRepository.FindOne(map[string]interface{}{"userId":operatorId})
  21 + //if err!=nil{
  22 + // return nil,err
  23 + //}
  24 + //if operator.AdminType>=domain.NormalUser{
  25 + // return nil, fmt.Errorf("权限不足")
  26 + //}
  27 + if user.UserType&domain.Partner > 0 {
  28 + if user.PartnerInfo == nil {
  29 + return nil, fmt.Errorf("合伙人信息不能为空")
  30 + }
  31 + }
  32 + user, err = UserRepository.Save(user)
  33 + if err != nil {
  34 + return nil, err
  35 + }
  36 +
  37 + PhoneAuthenticationService, _ := NewPhoneAuthenticationService(service.transactionContext)
  38 + if _, err = PhoneAuthenticationService.PhoneAuth(user.UserId, user.UserInfo.UserAccount, ""); err != nil {
  39 + return nil, err
  40 + }
  41 + return user, err
  42 +}
  43 +
  44 +func NewUserCreateService(transactionContext *pgTransaction.TransactionContext) (*UserCreateService, error) {
  45 + if transactionContext == nil {
  46 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  47 + } else {
  48 + return &UserCreateService{
  49 + transactionContext: transactionContext,
  50 + }, nil
  51 + }
  52 +}
1 package pg 1 package pg
2 2
3 import ( 3 import (
  4 + "context"
4 "fmt" 5 "fmt"
5 "github.com/go-pg/pg/v10" 6 "github.com/go-pg/pg/v10"
6 "github.com/go-pg/pg/v10/orm" 7 "github.com/go-pg/pg/v10/orm"
7 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/constant" 8 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/constant"
8 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models" 9 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"
  10 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/log"
9 11
10 "github.com/linmadan/egglib-go/persistent/pg/hooks" 12 "github.com/linmadan/egglib-go/persistent/pg/hooks"
11 ) 13 )
@@ -43,3 +45,18 @@ func init() { @@ -43,3 +45,18 @@ func init() {
43 } 45 }
44 } 46 }
45 } 47 }
  48 +
  49 +type SqlGeneratePrintHook struct{}
  50 +
  51 +func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Context, error) {
  52 + return c, nil
  53 +}
  54 +
  55 +func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error {
  56 + sqlStr, err := q.FormattedQuery()
  57 + if err != nil {
  58 + return err
  59 + }
  60 + log.Logger.Debug(string(sqlStr))
  61 + return nil
  62 +}
@@ -98,6 +98,9 @@ func (repository *UserAuthRepository) FindOne(queryOptions map[string]interface{ @@ -98,6 +98,9 @@ func (repository *UserAuthRepository) FindOne(queryOptions map[string]interface{
98 userAuthModel := new(models.UserAuth) 98 userAuthModel := new(models.UserAuth)
99 query := sqlbuilder.BuildQuery(tx.Model(userAuthModel), queryOptions) 99 query := sqlbuilder.BuildQuery(tx.Model(userAuthModel), queryOptions)
100 query.SetWhereByQueryOption("user_auth.user_auth_id = ?", "userAuthId") 100 query.SetWhereByQueryOption("user_auth.user_auth_id = ?", "userAuthId")
  101 + if v, ok := queryOptions["userId"]; ok {
  102 + query.Where(fmt.Sprintf(`user_auth.users @>'{%v}'`, v))
  103 + }
101 if v, ok := queryOptions["phone"]; ok { 104 if v, ok := queryOptions["phone"]; ok {
102 query.Where(fmt.Sprintf(`user_auth.phone_auth @>'{"phone":"%v"}'`, v)) 105 query.Where(fmt.Sprintf(`user_auth.phone_auth @>'{"phone":"%v"}'`, v))
103 } 106 }
@@ -106,7 +109,7 @@ func (repository *UserAuthRepository) FindOne(queryOptions map[string]interface{ @@ -106,7 +109,7 @@ func (repository *UserAuthRepository) FindOne(queryOptions map[string]interface{
106 } 109 }
107 if err := query.First(); err != nil { 110 if err := query.First(); err != nil {
108 if err.Error() == "pg: no rows in result set" { 111 if err.Error() == "pg: no rows in result set" {
109 - return nil, fmt.Errorf("没有此资源") 112 + return nil, pg.ErrNoRows
110 } else { 113 } else {
111 return nil, err 114 return nil, err
112 } 115 }
@@ -16,7 +16,7 @@ func init() { @@ -16,7 +16,7 @@ func init() {
16 web.BConfig.RunMode = "dev" 16 web.BConfig.RunMode = "dev"
17 web.BConfig.Listen.HTTPPort = 8080 17 web.BConfig.Listen.HTTPPort = 8080
18 web.BConfig.Listen.EnableAdmin = false 18 web.BConfig.Listen.EnableAdmin = false
19 - web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego" 19 + web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers"
20 if os.Getenv("RUN_MODE") != "" { 20 if os.Getenv("RUN_MODE") != "" {
21 web.BConfig.RunMode = os.Getenv("RUN_MODE") 21 web.BConfig.RunMode = os.Getenv("RUN_MODE")
22 } 22 }
@@ -37,6 +37,8 @@ var _ = Describe("创建", func() { @@ -37,6 +37,8 @@ var _ = Describe("创建", func() {
37 }) 37 })
38 AfterEach(func() { 38 AfterEach(func() {
39 _, err := pG.DB.Exec("DELETE FROM companies WHERE true") 39 _, err := pG.DB.Exec("DELETE FROM companies WHERE true")
  40 + _, err = pG.DB.Exec("DELETE FROM users WHERE true")
  41 + _, err = pG.DB.Exec("DELETE FROM user_auth WHERE true")
40 Expect(err).NotTo(HaveOccurred()) 42 Expect(err).NotTo(HaveOccurred())
41 }) 43 })
42 }) 44 })
@@ -18,19 +18,19 @@ var _ = Describe("设置公司管理员", func() { @@ -18,19 +18,19 @@ var _ = Describe("设置公司管理员", func() {
18 var newCompany *domain.Company 18 var newCompany *domain.Company
19 BeforeEach(func() { 19 BeforeEach(func() {
20 newCompany = &domain.Company{ 20 newCompany = &domain.Company{
21 - CompanyId:GinkgoRandomSeed(), 21 + CompanyId: GinkgoRandomSeed(),
22 CompanyInfo: &domain.CompanyInfo{ 22 CompanyInfo: &domain.CompanyInfo{
23 - Name: "公司名称", // 公司名称 23 + Name: "公司名称", // 公司名称
24 Abbreviation: "公司简称", // 公司简称 24 Abbreviation: "公司简称", // 公司简称
25 - Logo: "", // 公司logo  
26 - Phone: "", // 公司联系电话  
27 - Status: 1, // 状态 1正常 2禁用  
28 - Remarks: "备注", // 备注  
29 - Enable: 1, // 是否有效【1:有效】【2:无效】 25 + Logo: "", // 公司logo
  26 + Phone: "", // 公司联系电话
  27 + Status: 1, // 状态 1正常 2禁用
  28 + Remarks: "备注", // 备注
  29 + Enable: 1, // 是否有效【1:有效】【2:无效】
30 Admin: &domain.CompanyAdmin{ 30 Admin: &domain.CompanyAdmin{
31 UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号 31 UserAccount: fmt.Sprint(GinkgoRandomSeed()), // 用户手机号
32 - UserName: "用户名称", // 用户名称  
33 - }, // 公司主管理员 32 + UserName: "用户名称", // 用户名称
  33 + }, // 公司主管理员
34 }, 34 },
35 CreateAt: time.Now(), 35 CreateAt: time.Now(),
36 UpdateAt: time.Now(), 36 UpdateAt: time.Now(),
@@ -67,6 +67,8 @@ var _ = Describe("设置公司管理员", func() { @@ -67,6 +67,8 @@ var _ = Describe("设置公司管理员", func() {
67 }) 67 })
68 AfterEach(func() { 68 AfterEach(func() {
69 _, err := pG.DB.Exec("DELETE FROM companies WHERE true") 69 _, err := pG.DB.Exec("DELETE FROM companies WHERE true")
  70 + _, err = pG.DB.Exec("DELETE FROM users WHERE true")
  71 + _, err = pG.DB.Exec("DELETE FROM user_auth WHERE true")
70 Expect(err).NotTo(HaveOccurred()) 72 Expect(err).NotTo(HaveOccurred())
71 }) 73 })
72 }) 74 })