作者 yangfu

注册修改、重定向、企业修改

正在显示 28 个修改的文件 包含 928 行增加108 行删除
@@ -7,6 +7,7 @@ require ( @@ -7,6 +7,7 @@ require (
7 github.com/beego/beego/v2 v2.0.1 7 github.com/beego/beego/v2 v2.0.1
8 github.com/dgrijalva/jwt-go v3.2.0+incompatible 8 github.com/dgrijalva/jwt-go v3.2.0+incompatible
9 github.com/disintegration/imaging v1.6.2 9 github.com/disintegration/imaging v1.6.2
  10 + github.com/emirpasic/gods v1.12.0
10 github.com/forgoer/openssl v0.0.0-20210828150411-6c5378b5b719 11 github.com/forgoer/openssl v0.0.0-20210828150411-6c5378b5b719
11 github.com/go-pg/pg/v10 v10.10.1 12 github.com/go-pg/pg/v10 v10.10.1
12 github.com/go-redis/redis v6.15.7+incompatible 13 github.com/go-redis/redis v6.15.7+incompatible
@@ -73,6 +73,8 @@ github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox @@ -73,6 +73,8 @@ github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox
73 github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk= 73 github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
74 github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= 74 github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
75 github.com/emicklei/proto v1.9.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= 75 github.com/emicklei/proto v1.9.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
  76 +github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
  77 +github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
76 github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 78 github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
77 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 79 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
78 github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 80 github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
@@ -2,6 +2,7 @@ package command @@ -2,6 +2,7 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
5 "reflect" 6 "reflect"
6 "strings" 7 "strings"
7 8
@@ -23,6 +24,15 @@ type CompanySignUpCommand struct { @@ -23,6 +24,15 @@ type CompanySignUpCommand struct {
23 Password string `cname:"密码" json:"password" valid:"Required"` 24 Password string `cname:"密码" json:"password" valid:"Required"`
24 // 短信验证码 25 // 短信验证码
25 SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"` 26 SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"`
  27 +
  28 + // 法人
  29 + LegalPerson string `cname:"法人" json:"legalPerson" valid:"Required"`
  30 + // 社会信用代码
  31 + SocialCreditCode string `cname:"社会信用代码" json:"socialCreditCode" valid:"Required"`
  32 + // 营业执照所在地
  33 + BusinessLicenseAddress domain.BusinessLicenseAddress `cname:"营业执照所在地" json:"businessLicenseAddress" valid:"Required"`
  34 + // 营业执照-附件
  35 + BusinessLicenseAttachments []domain.Attachment `cname:"营业执照-附件" json:"businessLicenseAttachments" valid:"Required"`
26 } 36 }
27 37
28 func (companySignUpCommand *CompanySignUpCommand) Valid(validation *validation.Validation) { 38 func (companySignUpCommand *CompanySignUpCommand) Valid(validation *validation.Validation) {
@@ -406,6 +406,11 @@ func (svr AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUp @@ -406,6 +406,11 @@ func (svr AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUp
406 Contacts: companySignUpCommand.Contacts, 406 Contacts: companySignUpCommand.Contacts,
407 IndustryCategory: companySignUpCommand.IndustryCategory, 407 IndustryCategory: companySignUpCommand.IndustryCategory,
408 Scale: companySignUpCommand.Scale, 408 Scale: companySignUpCommand.Scale,
  409 +
  410 + LegalPerson: companySignUpCommand.LegalPerson,
  411 + SocialCreditCode: companySignUpCommand.SocialCreditCode,
  412 + BusinessLicenseAttachments: companySignUpCommand.BusinessLicenseAttachments,
  413 + BusinessLicenseAddress: companySignUpCommand.BusinessLicenseAddress,
409 }) 414 })
410 if err != nil { 415 if err != nil {
411 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 416 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -629,7 +634,7 @@ func (svr AuthService) matchUser(loginToken *domain.LoginToken) (*allied_creatio @@ -629,7 +634,7 @@ func (svr AuthService) matchUser(loginToken *domain.LoginToken) (*allied_creatio
629 loopUser1: 634 loopUser1:
630 for _, v := range userSearchResult.Users { 635 for _, v := range userSearchResult.Users {
631 for _, vv := range v.UserOrg { 636 for _, vv := range v.UserOrg {
632 - if vv.OrgID == int(loginToken.OrgId) { 637 + if vv.OrgID == int(loginToken.OrgId) && v.Company.Status == domain.CompanyAuthenticated {
633 currentOrgIsOK = true 638 currentOrgIsOK = true
634 currentUser = v 639 currentUser = v
635 break loopUser1 640 break loopUser1
@@ -713,6 +718,9 @@ func (svr AuthService) GetCompanyOrgsByUser(queryParam *query.GetCompanyOrgsByUs @@ -713,6 +718,9 @@ func (svr AuthService) GetCompanyOrgsByUser(queryParam *query.GetCompanyOrgsByUs
713 CompanyId: user.Company.CompanyId, 718 CompanyId: user.Company.CompanyId,
714 CompanyName: user.Company.CompanyName, 719 CompanyName: user.Company.CompanyName,
715 }) 720 })
  721 + if user.Company.Status != domain.CompanyAuthenticated {
  722 + continue
  723 + }
716 } 724 }
717 for j := range user.UserOrg { 725 for j := range user.UserOrg {
718 org := user.UserOrg[j] 726 org := user.UserOrg[j]
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type AuditCompanyCommand struct {
  12 + // 企业id
  13 + CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"`
  14 + // 审核状态
  15 + Status int `cname:"审核状态" json:"status" valid:"Required"`
  16 + // 备注
  17 + Remark string `cname:"备注" json:"remark" valid:"Required"`
  18 +}
  19 +
  20 +func (updateCompanyCommand *AuditCompanyCommand) Valid(validation *validation.Validation) {
  21 + //validation.SetError("CustomValid", "未实现的自定义认证")
  22 +}
  23 +
  24 +func (updateCompanyCommand *AuditCompanyCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(updateCompanyCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + elem := reflect.TypeOf(updateCompanyCommand).Elem()
  32 + for _, validErr := range valid.Errors {
  33 + field, isExist := elem.FieldByName(validErr.Field)
  34 + if isExist {
  35 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  36 + } else {
  37 + return fmt.Errorf(validErr.Message)
  38 + }
  39 + }
  40 + }
  41 + return nil
  42 +}
  1 +package command
  2 +
  3 +// type CreateCompanyCommand struct {
  4 +// // 企业名称
  5 +// CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"`
  6 +// // 规模
  7 +// Scale string `cname:"规模" json:"scale" valid:"Required"`
  8 +// // 公司Logo地址
  9 +// Logo string `cname:"公司Logo地址" json:"logo" valid:"Required"`
  10 +// // 公司地址
  11 +// Address string `cname:"公司地址" json:"address" valid:"Required"`
  12 +// // 所属行业
  13 +// IndustryCategory string `cname:"所属行业" json:"industryCategory" valid:"Required"`
  14 +// // 联系人
  15 +// Contacts string `cname:"联系人" json:"contacts" valid:"Required"`
  16 +// // 注册时间
  17 +// RegisteredTime time.Time `cname:"注册时间" json:"registeredTime,omitempty"`
  18 +// // 注册状态 1:已注册 2:待认证 3:已认证
  19 +// Status int `cname:"注册状态 1:已注册 2:待认证 3:已认证" json:"status,omitempty"`
  20 +// }
  21 +
  22 +// func (createCompanyCommand *CreateCompanyCommand) Valid(validation *validation.Validation) {
  23 +
  24 +// }
  25 +
  26 +// func (createCompanyCommand *CreateCompanyCommand) ValidateCommand() error {
  27 +// valid := validation.Validation{}
  28 +// b, err := valid.Valid(createCompanyCommand)
  29 +// if err != nil {
  30 +// return err
  31 +// }
  32 +// if !b {
  33 +// elem := reflect.TypeOf(createCompanyCommand).Elem()
  34 +// for _, validErr := range valid.Errors {
  35 +// field, isExist := elem.FieldByName(validErr.Field)
  36 +// if isExist {
  37 +// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  38 +// } else {
  39 +// return fmt.Errorf(validErr.Message)
  40 +// }
  41 +// }
  42 +// }
  43 +// return nil
  44 +// }
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type EnableCompanyCommand struct {
  12 + // 企业id
  13 + CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"`
  14 + // 审核状态
  15 + Status int `cname:"审核状态" json:"status" valid:"Required"`
  16 +}
  17 +
  18 +func (updateCompanyCommand *EnableCompanyCommand) Valid(validation *validation.Validation) {
  19 + //validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (updateCompanyCommand *EnableCompanyCommand) ValidateCommand() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(updateCompanyCommand)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + elem := reflect.TypeOf(updateCompanyCommand).Elem()
  30 + for _, validErr := range valid.Errors {
  31 + field, isExist := elem.FieldByName(validErr.Field)
  32 + if isExist {
  33 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  34 + } else {
  35 + return fmt.Errorf(validErr.Message)
  36 + }
  37 + }
  38 + }
  39 + return nil
  40 +}
  1 +package command
  2 +
  3 +// type ListCompanyCustomizeMenusCommand struct {
  4 +// // 企业id
  5 +// CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
  6 +// // 菜单类别 web app
  7 +// MenuCategory string `cname:"菜单类别" json:"menuCategory,omitempty" valid:"Required"`
  8 +// }
  9 +
  10 +// func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
  11 +
  12 +// }
  13 +
  14 +// func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) ValidateCommand() error {
  15 +// valid := validation.Validation{}
  16 +// b, err := valid.Valid(listCompanyCustomizeMenusCommand)
  17 +// if err != nil {
  18 +// return err
  19 +// }
  20 +// if !b {
  21 +// elem := reflect.TypeOf(listCompanyCustomizeMenusCommand).Elem()
  22 +// for _, validErr := range valid.Errors {
  23 +// field, isExist := elem.FieldByName(validErr.Field)
  24 +// if isExist {
  25 +// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  26 +// } else {
  27 +// return fmt.Errorf(validErr.Message)
  28 +// }
  29 +// }
  30 +// }
  31 +// return nil
  32 +// }
  1 +package command
  2 +
  3 +// type RemoveCompanyCommand struct {
  4 +// // 企业id
  5 +// CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
  6 +// }
  7 +
  8 +// func (removeCompanyCommand *RemoveCompanyCommand) Valid(validation *validation.Validation) {
  9 +// validation.SetError("CustomValid", "未实现的自定义认证")
  10 +// }
  11 +
  12 +// func (removeCompanyCommand *RemoveCompanyCommand) ValidateCommand() error {
  13 +// valid := validation.Validation{}
  14 +// b, err := valid.Valid(removeCompanyCommand)
  15 +// if err != nil {
  16 +// return err
  17 +// }
  18 +// if !b {
  19 +// elem := reflect.TypeOf(removeCompanyCommand).Elem()
  20 +// for _, validErr := range valid.Errors {
  21 +// field, isExist := elem.FieldByName(validErr.Field)
  22 +// if isExist {
  23 +// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  24 +// } else {
  25 +// return fmt.Errorf(validErr.Message)
  26 +// }
  27 +// }
  28 +// }
  29 +// return nil
  30 +// }
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type UpdateCompanyCommand struct {
  13 + //操作人
  14 + Operator domain.Operator `json:"-"`
  15 + // 企业名称
  16 + CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"`
  17 + // 公司地址
  18 + Address string `cname:"公司地址" json:"address" valid:"Required"`
  19 + // 系统名称
  20 + SystemName string `cname:"系统名称" json:"systemName" valid:"Required"`
  21 + // 公司Logo地址
  22 + Logo string `cname:"公司Logo地址" json:"logo" valid:"Required"`
  23 +}
  24 +
  25 +func (updateCompanyCommand *UpdateCompanyCommand) Valid(validation *validation.Validation) {
  26 + validation.SetError("CustomValid", "未实现的自定义认证")
  27 +}
  28 +
  29 +func (updateCompanyCommand *UpdateCompanyCommand) ValidateCommand() error {
  30 + valid := validation.Validation{}
  31 + b, err := valid.Valid(updateCompanyCommand)
  32 + if err != nil {
  33 + return err
  34 + }
  35 + if !b {
  36 + elem := reflect.TypeOf(updateCompanyCommand).Elem()
  37 + for _, validErr := range valid.Errors {
  38 + field, isExist := elem.FieldByName(validErr.Field)
  39 + if isExist {
  40 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  41 + } else {
  42 + return fmt.Errorf(validErr.Message)
  43 + }
  44 + }
  45 + }
  46 + return nil
  47 +}
  1 +package command
  2 +
  3 +// type UpdateCompanyCustomizeMenusCommand struct {
  4 +// // 企业id
  5 +// CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"`
  6 +// // 菜单编号
  7 +// MenuId int64 `cname:"菜单编号" json:"menuId" valid:"Required"`
  8 +// // 菜单名称
  9 +// //MenuName string `cname:"菜单名称" json:"menuName" valid:"Required"`
  10 +// // 菜单别名
  11 +// MenuAlias string `cname:"菜单别名" json:"menuAlias" valid:"Required"`
  12 +// // 排序
  13 +// Sort int `cname:"排序" json:"sort" valid:"Required"`
  14 +// }
  15 +
  16 +// func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
  17 +// //validation.SetError("CustomValid", "未实现的自定义认证")
  18 +// }
  19 +
  20 +// func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) ValidateCommand() error {
  21 +// valid := validation.Validation{}
  22 +// b, err := valid.Valid(updateCompanyCustomizeMenusCommand)
  23 +// if err != nil {
  24 +// return err
  25 +// }
  26 +// if !b {
  27 +// elem := reflect.TypeOf(updateCompanyCustomizeMenusCommand).Elem()
  28 +// for _, validErr := range valid.Errors {
  29 +// field, isExist := elem.FieldByName(validErr.Field)
  30 +// if isExist {
  31 +// return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 +// } else {
  33 +// return fmt.Errorf(validErr.Message)
  34 +// }
  35 +// }
  36 +// }
  37 +// return nil
  38 +// }
  1 +package dto
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  6 +)
  7 +
  8 +type CompanyGetItemDto struct {
  9 + CompanyListItemDto
  10 + Remark string `json:"remark"`
  11 +
  12 + // 法律相关
  13 + // 法人
  14 + LegalPerson string `json:"legalPerson"`
  15 + // 社会信用代码
  16 + SocialCreditCode string `json:"socialCreditCode"`
  17 + // 营业执照所在地
  18 + BusinessLicenseAddress interface{} `json:"businessLicenseAddress"`
  19 + // 营业执照-附件
  20 + BusinessLicenseAttachments []domain.Attachment `json:"businessLicenseAttachments"`
  21 +}
  22 +
  23 +func (dto *CompanyGetItemDto) LoadDto(c allied_creation_user.CompanyItem, u allied_creation_user.UserDetail) {
  24 + companyListItemDto := &CompanyListItemDto{}
  25 + companyListItemDto.LoadDto(c, u)
  26 + dto.CompanyListItemDto = *companyListItemDto
  27 + dto.Remark = c.CompanyInfo.Remark
  28 + dto.LegalPerson = c.CompanyInfo.Legal.LegalPerson
  29 + dto.SocialCreditCode = c.CompanyInfo.Legal.SocialCreditCode
  30 + dto.BusinessLicenseAddress = c.CompanyInfo.Legal.BusinessLicenseAddress
  31 + dto.BusinessLicenseAttachments = c.CompanyInfo.Legal.BusinessLicenseAttachments
  32 +}
  1 +package dto
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  4 +
  5 +type CompanyListItemDto struct {
  6 + // 企业id
  7 + CompanyId int `json:"companyId"`
  8 + // 公司名称
  9 + CompanyName string `json:"companyName"`
  10 + // 规模
  11 + Scale string `json:"scale,omitempty"`
  12 + // 所属行业
  13 + IndustryCategory string `json:"industryCategory,omitempty"`
  14 + // 联系人
  15 + Contacts string `cname:"联系人" json:"contacts"`
  16 + // 手机号码
  17 + Phone string `cname:"手机号码" json:"phone"`
  18 + // 注册时间
  19 + RegisteredTime string `json:"registeredTime,omitempty"`
  20 + // 公司状态 1:已注册(待审核) 2:已通过 3:已拒绝
  21 + Status int `json:"status"`
  22 +}
  23 +
  24 +func (dto *CompanyListItemDto) LoadDto(c allied_creation_user.CompanyItem, u allied_creation_user.UserDetail) *CompanyListItemDto {
  25 + dto.CompanyId = c.CompanyId
  26 + dto.CompanyName = c.CompanyInfo.CompanyName
  27 + dto.Scale = c.CompanyInfo.Scale
  28 + dto.IndustryCategory = c.CompanyInfo.IndustryCategory
  29 + dto.Contacts = u.UserInfo.UserName
  30 + dto.Phone = u.UserInfo.Phone
  31 + dto.RegisteredTime = c.CompanyInfo.RegisteredTime.Format("2006-01-02")
  32 + dto.Status = c.Status
  33 + return dto
  34 +}
  35 +
  36 +type CompanyListItemsDto []*CompanyListItemDto
  37 +
  38 +func (dto *CompanyListItemsDto) LoadDto(items []allied_creation_user.CompanyItem, users []allied_creation_user.UserDetail) {
  39 + var mapItems = make(map[int]allied_creation_user.CompanyItem)
  40 + for i := range items {
  41 + mapItems[items[i].CompanyId] = items[i]
  42 + }
  43 + for i := range users {
  44 + if v, ok := mapItems[users[i].Company.CompanyId]; ok {
  45 + company := &CompanyListItemDto{}
  46 + *dto = append(*dto, company.LoadDto(v, users[i]))
  47 + }
  48 + }
  49 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type GetCompanyQuery struct {
  12 + // 企业id
  13 + CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
  14 +}
  15 +
  16 +func (getCompanyQuery *GetCompanyQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (getCompanyQuery *GetCompanyQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(getCompanyQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + elem := reflect.TypeOf(getCompanyQuery).Elem()
  28 + for _, validErr := range valid.Errors {
  29 + field, isExist := elem.FieldByName(validErr.Field)
  30 + if isExist {
  31 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  32 + } else {
  33 + return fmt.Errorf(validErr.Message)
  34 + }
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/beego/beego/v2/core/validation"
  6 + "reflect"
  7 + "strings"
  8 +)
  9 +
  10 +type ListCompanyQuery struct {
  11 + // 查询偏离量
  12 + PageNumber int `json:"pageNumber"`
  13 + // 查询限制
  14 + PageSize int `json:"pageSize" valid:"Required"`
  15 + // 状态
  16 + Status int `cname:"状态" json:"status,omitempty"`
  17 + // 企业名称
  18 + CompanyName string `cname:"企业名称" json:"companyName,omitempty"`
  19 +}
  20 +
  21 +func (listCompanyQuery *ListCompanyQuery) Valid(validation *validation.Validation) {
  22 +
  23 +}
  24 +
  25 +func (listCompanyQuery *ListCompanyQuery) ValidateQuery() error {
  26 + valid := validation.Validation{}
  27 + b, err := valid.Valid(listCompanyQuery)
  28 + if err != nil {
  29 + return err
  30 + }
  31 + if !b {
  32 + elem := reflect.TypeOf(listCompanyQuery).Elem()
  33 + for _, validErr := range valid.Errors {
  34 + field, isExist := elem.FieldByName(validErr.Field)
  35 + if isExist {
  36 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  37 + } else {
  38 + return fmt.Errorf(validErr.Message)
  39 + }
  40 + }
  41 + }
  42 + return nil
  43 +}
  1 +package service
  2 +
  3 +import (
  4 + "github.com/emirpasic/gods/sets/hashset"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/dto"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/query"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  11 +)
  12 +
  13 +// 企业
  14 +type CompanyService struct {
  15 +}
  16 +
  17 +// 创建企业
  18 +// func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) {
  19 +// return nil, nil
  20 +// }
  21 +
  22 +// 返回企业
  23 +func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompanyQuery) (interface{}, error) {
  24 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  25 + result, err := creationUserGateway.CompanyGet(allied_creation_user.ReqCompanyGet{
  26 + CompanyId: getCompanyQuery.CompanyId,
  27 + })
  28 + if err != nil {
  29 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  30 + }
  31 + userResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
  32 + InCompanyIds: []interface{}{result.CompanyId},
  33 + UserType: domain.UserTypeCompanyAdmin,
  34 + })
  35 + if err != nil {
  36 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  37 + }
  38 + var user allied_creation_user.UserDetail
  39 + if len(userResult.Users) > 0 {
  40 + user = userResult.Users[0]
  41 + }
  42 + companyDto := &dto.CompanyGetItemDto{}
  43 + companyDto.LoadDto(allied_creation_user.CompanyItem(*result), user)
  44 + return companyDto, nil
  45 +}
  46 +
  47 +func (companyService *CompanyService) AuditCompany(cmd *command.AuditCompanyCommand) (interface{}, error) {
  48 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  49 + _, err := creationUserGateway.AuditCompany(allied_creation_user.ReqCompanyAudit{
  50 + CompanyId: int(cmd.CompanyId),
  51 + Status: cmd.Status,
  52 + Remark: cmd.Remark,
  53 + })
  54 + if err != nil {
  55 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  56 + }
  57 + return struct{}{}, nil
  58 +}
  59 +
  60 +func (companyService *CompanyService) EnableCompany(cmd *command.EnableCompanyCommand) (interface{}, error) {
  61 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  62 + _, err := creationUserGateway.EnableCompany(allied_creation_user.ReqCompanyEnable{
  63 + CompanyId: int(cmd.CompanyId),
  64 + Status: cmd.Status,
  65 + })
  66 + if err != nil {
  67 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  68 + }
  69 + return struct{}{}, nil
  70 +}
  71 +
  72 +// 返回企业列表
  73 +func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (int64, interface{}, error) {
  74 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  75 + result, err := creationUserGateway.CompanySearch(allied_creation_user.ReqCompanySearch{
  76 + Offset: (listCompanyQuery.PageNumber - 1) * listCompanyQuery.PageSize,
  77 + Limit: listCompanyQuery.PageSize,
  78 + Status: listCompanyQuery.Status,
  79 + CompanyName: listCompanyQuery.CompanyName,
  80 + })
  81 + if err != nil {
  82 + return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  83 + }
  84 + companySet := hashset.New()
  85 + for i := range result.Companys {
  86 + companySet.Add(result.Companys[i].CompanyId)
  87 + }
  88 + var users = make([]allied_creation_user.UserDetail, 0)
  89 + if companySet.Size() > 0 {
  90 + userResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
  91 + InCompanyIds: companySet.Values(),
  92 + UserType: domain.UserTypeCompanyAdmin,
  93 + })
  94 + if err != nil {
  95 + return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  96 + }
  97 + users = userResult.Users
  98 + }
  99 + companyListItemsDto := dto.CompanyListItemsDto{}
  100 + companyListItemsDto.LoadDto(result.Companys, users)
  101 + return 0, companyListItemsDto, nil
  102 +}
  103 +
  104 +// 返回自定义菜单列表(匹配有设置的菜单)
  105 +// func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand *command.ListCompanyCustomizeMenusCommand) (interface{}, error) {
  106 +// return nil, nil
  107 +// }
  108 +
  109 +// 移除企业
  110 +// func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) {
  111 +// return nil, nil
  112 +// }
  113 +
  114 +// 更新企业
  115 +func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *command.UpdateCompanyCommand) (interface{}, error) {
  116 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(updateCompanyCommand.Operator)
  117 + _, err := creationUserGateway.CompanyUpdate(allied_creation_user.ReqCompanyUpdate{
  118 + CompanyId: updateCompanyCommand.Operator.CompanyId,
  119 + CompanyName: updateCompanyCommand.CompanyName,
  120 + Address: updateCompanyCommand.Address,
  121 + SystemName: updateCompanyCommand.SystemName,
  122 + Logo: updateCompanyCommand.Logo,
  123 + })
  124 + if err != nil {
  125 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  126 + }
  127 + return updateCompanyCommand, nil
  128 +}
  129 +
  130 +func NewCompanyService(options map[string]interface{}) *CompanyService {
  131 + newCompanyService := &CompanyService{}
  132 + return newCompanyService
  133 +}
1 package domain 1 package domain
2 2
  3 +// 公司状态状态 1:已注册 2:已通过 3:已拒绝
  4 +const (
  5 + CompanyRegistered = iota + 1
  6 + CompanyAuthenticated
  7 + CompanyUnauthenticated
  8 +)
  9 +
3 //公司 10 //公司
4 type CompanyData struct { 11 type CompanyData struct {
5 CompanyID int `json:"companyId"` 12 CompanyID int `json:"companyId"`
@@ -12,3 +19,10 @@ type Company struct { @@ -12,3 +19,10 @@ type Company struct {
12 Logo string `json:"logo"` 19 Logo string `json:"logo"`
13 CompanyName string `json:"companyName"` 20 CompanyName string `json:"companyName"`
14 } 21 }
  22 +
  23 +// 营业执照所在地
  24 +type BusinessLicenseAddress struct {
  25 + Province string `json:"province"`
  26 + City string `json:"city"`
  27 + Address string `json:"address"`
  28 +}
@@ -28,3 +28,7 @@ func NewHttplibAlliedCreationUser(operator domain.Operator) *HttplibAlliedCreati @@ -28,3 +28,7 @@ func NewHttplibAlliedCreationUser(operator domain.Operator) *HttplibAlliedCreati
28 } 28 }
29 29
30 } 30 }
  31 +
  32 +func (gateway HttplibAlliedCreationUser) BaseUrl() string {
  33 + return gateway.baseUrL
  34 +}
@@ -135,7 +135,7 @@ func (gateway HttplibAlliedCreationUser) CompanyRemove(param ReqCompanyRemove) ( @@ -135,7 +135,7 @@ func (gateway HttplibAlliedCreationUser) CompanyRemove(param ReqCompanyRemove) (
135 135
136 // CompanyGet 返回企业 136 // CompanyGet 返回企业
137 func (gateway HttplibAlliedCreationUser) CompanyGet(param ReqCompanyGet) (*DataCompanyGet, error) { 137 func (gateway HttplibAlliedCreationUser) CompanyGet(param ReqCompanyGet) (*DataCompanyGet, error) {
138 - url := gateway.baseUrL + "/company/{companyId}" 138 + url := gateway.baseUrL + "/company/" + strconv.Itoa(param.CompanyId)
139 method := "GET" 139 method := "GET"
140 req := gateway.CreateRequest(url, method) 140 req := gateway.CreateRequest(url, method)
141 log.Logger.Debug("向用户模块请求数据:返回企业。", map[string]interface{}{ 141 log.Logger.Debug("向用户模块请求数据:返回企业。", map[string]interface{}{
@@ -164,6 +164,66 @@ func (gateway HttplibAlliedCreationUser) CompanyGet(param ReqCompanyGet) (*DataC @@ -164,6 +164,66 @@ func (gateway HttplibAlliedCreationUser) CompanyGet(param ReqCompanyGet) (*DataC
164 return &data, err 164 return &data, err
165 } 165 }
166 166
  167 +func (gateway HttplibAlliedCreationUser) AuditCompany(param ReqCompanyAudit) (DataCompanyAudit, error) {
  168 + url := gateway.baseUrL + fmt.Sprintf("/company/%d/audit", param.CompanyId)
  169 + method := "post"
  170 + req := gateway.CreateRequest(url, method)
  171 + moduleDesc := "审核公司"
  172 + //TODO traceID
  173 + log.Logger.Debug("向用户模块请求数据:"+moduleDesc, map[string]interface{}{
  174 + "api": method + ":" + url,
  175 + "param": param,
  176 + })
  177 + req, err := req.JSONBody(param)
  178 + if err != nil {
  179 + return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
  180 + }
  181 +
  182 + byteResult, err := req.Bytes()
  183 + if err != nil {
  184 + return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
  185 + }
  186 +
  187 + var result service_gateway.GatewayResponse
  188 + err = json.Unmarshal(byteResult, &result)
  189 + if err != nil {
  190 + return nil, fmt.Errorf("解析错误:%w", err)
  191 + }
  192 + var data DataCompanyAudit
  193 + err = gateway.GetResponseData(result, &data)
  194 + return data, err
  195 +}
  196 +
  197 +func (gateway HttplibAlliedCreationUser) EnableCompany(param ReqCompanyEnable) (DataCompanyEnable, error) {
  198 + url := gateway.baseUrL + fmt.Sprintf("/company/%d/enable", param.CompanyId)
  199 + method := "post"
  200 + req := gateway.CreateRequest(url, method)
  201 + moduleDesc := "启用公司"
  202 + //TODO traceID
  203 + log.Logger.Debug("向用户模块请求数据:"+moduleDesc, map[string]interface{}{
  204 + "api": method + ":" + url,
  205 + "param": param,
  206 + })
  207 + req, err := req.JSONBody(param)
  208 + if err != nil {
  209 + return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
  210 + }
  211 +
  212 + byteResult, err := req.Bytes()
  213 + if err != nil {
  214 + return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
  215 + }
  216 +
  217 + var result service_gateway.GatewayResponse
  218 + err = json.Unmarshal(byteResult, &result)
  219 + if err != nil {
  220 + return nil, fmt.Errorf("解析错误:%w", err)
  221 + }
  222 + var data DataCompanyEnable
  223 + err = gateway.GetResponseData(result, &data)
  224 + return data, err
  225 +}
  226 +
167 // CompanySearch 返回企业列表 227 // CompanySearch 返回企业列表
168 func (gateway HttplibAlliedCreationUser) CompanySearch(param ReqCompanySearch) (*DataCompanySearch, error) { 228 func (gateway HttplibAlliedCreationUser) CompanySearch(param ReqCompanySearch) (*DataCompanySearch, error) {
169 url := gateway.baseUrL + "/company/search" 229 url := gateway.baseUrL + "/company/search"
1 package allied_creation_user 1 package allied_creation_user
2 2
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  4 +
3 //企业注册 5 //企业注册
4 type ( 6 type (
5 ReqAuthCompanySignUp struct { 7 ReqAuthCompanySignUp struct {
@@ -9,6 +11,15 @@ type ( @@ -9,6 +11,15 @@ type (
9 Password string `json:"password"` 11 Password string `json:"password"`
10 Phone string `json:"phone"` 12 Phone string `json:"phone"`
11 Scale string `json:"scale"` 13 Scale string `json:"scale"`
  14 +
  15 + // 法人
  16 + LegalPerson string `cname:"法人" json:"legalPerson" valid:"Required"`
  17 + // 社会信用代码
  18 + SocialCreditCode string `cname:"社会信用代码" json:"socialCreditCode" valid:"Required"`
  19 + // 营业执照所在地
  20 + BusinessLicenseAddress domain.BusinessLicenseAddress `cname:"营业执照所在地" json:"businessLicenseAddress" valid:"Required"`
  21 + // 营业执照-附件
  22 + BusinessLicenseAttachments []domain.Attachment `cname:"营业执照-附件" json:"businessLicenseAttachments" valid:"Required"`
12 } 23 }
13 24
14 DataAuthCompanySignUp struct { 25 DataAuthCompanySignUp struct {
1 package allied_creation_user 1 package allied_creation_user
2 2
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  5 + "time"
  6 +)
  7 +
3 //创建企业 8 //创建企业
4 type ( 9 type (
5 ReqCompanyCreate struct { 10 ReqCompanyCreate struct {
@@ -49,18 +54,78 @@ type ( @@ -49,18 +54,78 @@ type (
49 //返回企业 54 //返回企业
50 type ( 55 type (
51 ReqCompanyGet struct { 56 ReqCompanyGet struct {
  57 + CompanyId int `json:"companyId"`
52 } 58 }
53 59
54 - DataCompanyGet struct { 60 + DataCompanyGet CompanyItem
  61 +)
  62 +
  63 +type (
  64 + ReqCompanyAudit struct {
  65 + CompanyId int `json:"-"`
  66 + // 审核状态
  67 + Status int `cname:"审核状态" json:"status" valid:"Required"`
  68 + // 备注
  69 + Remark string `cname:"备注" json:"remark" valid:"Required"`
55 } 70 }
  71 +
  72 + DataCompanyAudit map[string]interface{}
  73 +)
  74 +
  75 +type (
  76 + ReqCompanyEnable struct {
  77 + CompanyId int `json:"-"`
  78 + // 审核状态
  79 + Status int `cname:"审核状态" json:"status" valid:"Required"`
  80 + }
  81 +
  82 + DataCompanyEnable map[string]interface{}
56 ) 83 )
57 84
58 //返回企业列表 85 //返回企业列表
59 type ( 86 type (
60 ReqCompanySearch struct { 87 ReqCompanySearch struct {
  88 + // 查询偏离量
  89 + Offset int `cname:"查询偏离量" json:"offset,omitempty"`
  90 + // 查询限制
  91 + Limit int `cname:"查询限制" json:"limit,omitempty"`
  92 + // 状态
  93 + Status int `cname:"状态" json:"status,omitempty"`
  94 + // 企业名称
  95 + CompanyName string `cname:"企业名称" json:"companyName,omitempty"`
61 } 96 }
62 97
63 DataCompanySearch struct { 98 DataCompanySearch struct {
  99 + Companys []CompanyItem `json:"companys"`
  100 + Count int `json:"count"`
  101 + }
  102 +
  103 + CompanyItem struct {
  104 + CompanyId int `json:"companyId"`
  105 + CompanyConfig struct {
  106 + SystemName string `json:"systemName"`
  107 + Theme string `json:"theme"`
  108 + } `json:"companyConfig"`
  109 + CompanyInfo struct {
  110 + CompanyName string `json:"companyName"`
  111 + Scale string `json:"scale"`
  112 + IndustryCategory string `json:"industryCategory"`
  113 + RegisteredTime time.Time `json:"registeredTime"`
  114 + Legal struct {
  115 + LegalPerson string `json:"legalPerson"`
  116 + SocialCreditCode string `json:"socialCreditCode"`
  117 + BusinessLicenseAddress struct {
  118 + Province string `json:"province"`
  119 + City string `json:"city"`
  120 + Address string `json:"address"`
  121 + } `json:"businessLicenseAddress"`
  122 + BusinessLicenseAttachments []domain.Attachment `json:"businessLicenseAttachments"`
  123 + } `json:"legal"`
  124 + Remark string `json:"备注"`
  125 + } `json:"companyInfo"`
  126 + Status int `json:"status"`
  127 + CreatedAt time.Time `json:"createdAt"`
  128 + UpdatedAt time.Time `json:"updatedAt"`
64 } 129 }
65 ) 130 )
66 131
@@ -106,6 +106,8 @@ type ( @@ -106,6 +106,8 @@ type (
106 EnableStatus int `cname:"状态(1:启用 2:禁用 3:注销)" json:"enableStatus,omitempty"` 106 EnableStatus int `cname:"状态(1:启用 2:禁用 3:注销)" json:"enableStatus,omitempty"`
107 // 状态(1:启用 2:禁用 3:注销) 107 // 状态(1:启用 2:禁用 3:注销)
108 InEnableStatus []int `cname:"状态(1:启用 2:禁用 3:注销)" json:"inEnableStatus,omitempty"` 108 InEnableStatus []int `cname:"状态(1:启用 2:禁用 3:注销)" json:"inEnableStatus,omitempty"`
  109 + // 匹配多个公司
  110 + InCompanyIds []interface{} `json:"inCompanyIds,omitempty"`
109 111
110 // 自定义高级查询 112 // 自定义高级查询
111 AdvancedQuery string `json:"advancedQuery"` 113 AdvancedQuery string `json:"advancedQuery"`
1 package beego 1 package beego
2 2
3 import ( 3 import (
4 - "encoding/json" 4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
5 "net/http" 6 "net/http"
6 "os" 7 "os"
7 "strconv" 8 "strconv"
@@ -48,25 +49,24 @@ func init() { @@ -48,25 +49,24 @@ func init() {
48 filters.SecureKeyMap["token"] = "x-mmm-accesstoken" 49 filters.SecureKeyMap["token"] = "x-mmm-accesstoken"
49 web.InsertFilter("/*", web.BeforeRouter, AllowCors()) 50 web.InsertFilter("/*", web.BeforeRouter, AllowCors())
50 web.InsertFilter("/*", web.BeforeRouter, filters.CreateRequstLogFilter(log.Logger)) 51 web.InsertFilter("/*", web.BeforeRouter, filters.CreateRequstLogFilter(log.Logger))
51 - web.InsertFilter("/v1/web/*", web.BeforeExec, middleware.CheckAccessToken2())  
52 - web.InsertFilter("/v1/app/*", web.BeforeExec, middleware.CheckAccessToken2())  
53 - web.InsertFilter("/v1/user/*", web.BeforeExec, middleware.CheckAccessToken2()) 52 + web.InsertFilter("/v1/web/*", web.BeforeExec, middleware.CheckAccessToken())
  53 + web.InsertFilter("/v1/app/*", web.BeforeExec, middleware.CheckAccessToken())
  54 + web.InsertFilter("/v1/user/*", web.BeforeExec, middleware.CheckAccessToken())
54 web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(log.Logger), web.WithReturnOnOutput(false)) 55 web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(log.Logger), web.WithReturnOnOutput(false))
55 - web.InsertFilter("/v1/app11/*", web.BeforeExec, filters.SecureHandler(  
56 - filters.WithEnableCheckTimestamp(false),  
57 - filters.WithOnInvalidRequest(func(ctx *context.Context) {  
58 - headerData, _ := json.Marshal(ctx.Input.Context.Request.Header)  
59 - log.Logger.Info("签名验证失败:" + string(headerData))  
60 - }),  
61 - ))  
62 - //web.InsertFilterChain("/v1/*", middleware.CheckAccessToken) 56 + //web.InsertFilter("/v1/app11/*", web.BeforeExec, filters.SecureHandler(
  57 + // filters.WithEnableCheckTimestamp(false),
  58 + // filters.WithOnInvalidRequest(func(ctx *context.Context) {
  59 + // headerData, _ := json.Marshal(ctx.Input.Context.Request.Header)
  60 + // log.Logger.Info("签名验证失败:" + string(headerData))
  61 + // }),
  62 + //))
  63 +
  64 + web.InsertFilter("/v1/common/user/area/*", web.BeforeRouter, middleware.RedirectInternalService("/v1/common/user", allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})))
63 } 65 }
64 66
65 func AllowCors() func(ctx *context.Context) { 67 func AllowCors() func(ctx *context.Context) {
66 return func(ctx *context.Context) { 68 return func(ctx *context.Context) {
67 ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH") 69 ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH")
68 - //ctx.Output.Header("Access-Control-Max-Age", "3600")  
69 - //ctx.Output.Header("Access-Control-Allow-Headers", "*,x-mmm-version")  
70 ctx.Output.Header("Access-Control-Allow-Headers", "Content-Type,X-Mmm-Accesstoken,X-Mmm-Devicetype,X-Mmm-Sign,X-Mmm-Timestamp,X-Mmm-Uuid,X-Mmm-Version,x-mmm-appname,*") 70 ctx.Output.Header("Access-Control-Allow-Headers", "Content-Type,X-Mmm-Accesstoken,X-Mmm-Devicetype,X-Mmm-Sign,X-Mmm-Timestamp,X-Mmm-Uuid,X-Mmm-Version,x-mmm-appname,*")
71 ctx.Output.Header("Access-Control-Allow-Credentials", "true") 71 ctx.Output.Header("Access-Control-Allow-Credentials", "true")
72 ctx.Output.Header("Access-Control-Allow-Origin", "*") //origin 72 ctx.Output.Header("Access-Control-Allow-Origin", "*") //origin
  1 +package backgroud_client
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/command"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/query"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/service"
  7 +)
  8 +
  9 +type CompanyController struct {
  10 + baseController
  11 +}
  12 +
  13 +// func (controller *CompanyController) CreateCompany() {
  14 +// companyService := service.NewCompanyService(nil)
  15 +// createCompanyCommand := &command.CreateCompanyCommand{}
  16 +// controller.Unmarshal(createCompanyCommand)
  17 +// data, err := companyService.CreateCompany(createCompanyCommand)
  18 +// controller.Response(data, err)
  19 +// }
  20 +
  21 +func (controller *CompanyController) UpdateCompany() {
  22 + companyService := service.NewCompanyService(nil)
  23 + updateCompanyCommand := &command.UpdateCompanyCommand{}
  24 + controller.Unmarshal(updateCompanyCommand)
  25 + updateCompanyCommand.Operator = controller.GetOperator()
  26 + data, err := companyService.UpdateCompany(updateCompanyCommand)
  27 + controller.Response(data, err)
  28 +}
  29 +
  30 +func (controller *CompanyController) GetCompany() {
  31 + companyService := service.NewCompanyService(nil)
  32 + getCompanyQuery := &query.GetCompanyQuery{}
  33 + companyId, _ := controller.GetInt(":companyId")
  34 + getCompanyQuery.CompanyId = companyId
  35 + data, err := companyService.GetCompany(getCompanyQuery)
  36 + controller.Response(data, err)
  37 +}
  38 +
  39 +// func (controller *CompanyController) RemoveCompany() {
  40 +// companyService := service.NewCompanyService(nil)
  41 +// removeCompanyCommand := &command.RemoveCompanyCommand{}
  42 +// controller.Unmarshal(removeCompanyCommand)
  43 +// companyId, _ := controller.GetInt64(":companyId")
  44 +// removeCompanyCommand.CompanyId = companyId
  45 +// data, err := companyService.RemoveCompany(removeCompanyCommand)
  46 +// controller.Response(data, err)
  47 +// }
  48 +
  49 +func (controller *CompanyController) SearchCompany() {
  50 + companyService := service.NewCompanyService(nil)
  51 + listCompanyQuery := &query.ListCompanyQuery{}
  52 + controller.Unmarshal(listCompanyQuery)
  53 + cnt, data, err := companyService.ListCompany(listCompanyQuery)
  54 + controller.returnPageListData(cnt, data, err, listCompanyQuery.PageNumber)
  55 +}
  56 +
  57 +func (controller *CompanyController) AuditCompany() {
  58 + companyService := service.NewCompanyService(nil)
  59 + cmd := &command.AuditCompanyCommand{}
  60 + controller.Unmarshal(cmd)
  61 + companyId, _ := controller.GetInt64(":companyId")
  62 + cmd.CompanyId = companyId
  63 + data, err := companyService.AuditCompany(cmd)
  64 + controller.Response(data, err)
  65 +}
  66 +
  67 +func (controller *CompanyController) EnableCompany() {
  68 + companyService := service.NewCompanyService(nil)
  69 + cmd := &command.EnableCompanyCommand{}
  70 + controller.Unmarshal(cmd)
  71 + companyId, _ := controller.GetInt64(":companyId")
  72 + cmd.CompanyId = companyId
  73 + data, err := companyService.EnableCompany(cmd)
  74 + controller.Response(data, err)
  75 +}
1 package middleware 1 package middleware
2 2
3 import ( 3 import (
4 - "fmt"  
5 - log1 "log"  
6 "net/http" 4 "net/http"
7 "net/url" 5 "net/url"
8 6
9 "github.com/beego/beego/v2/server/web" 7 "github.com/beego/beego/v2/server/web"
10 "github.com/beego/beego/v2/server/web/context" 8 "github.com/beego/beego/v2/server/web/context"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
12 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache"  
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
14 ) 11 )
15 12
16 type CtxKeyLoginToken struct{} 13 type CtxKeyLoginToken struct{}
17 14
18 -func JWTAuth(ctx *context.Context) {  
19 -  
20 -}  
21 -  
22 -func CheckAccessToken(next web.FilterFunc) web.FilterFunc {  
23 - return func(ctx *context.Context) {  
24 - tokenStr := ctx.Input.Header("x-mmm-accesstoken")  
25 - filterMap := map[string]string{  
26 - "/v1/auth/login/pwd": "",  
27 - "/v1/auth/login/sms": "",  
28 - "/v1/auth/login/qrcode": "",  
29 - "/v1/auth/org-switch": "",  
30 - "/v1/user/company-orgs": "",  
31 - "/v1/auth/captcha-init": "",  
32 - "/v1/auth/qrcode-init": "",  
33 - "/v1/auth/sms-code": "",  
34 - "/v1/auth/check-sms-code": "",  
35 - "/v1/auth/company-sign-up": "",  
36 - "/v1/auth/reset-password": "",  
37 - "/v1/auth/refresh-token": "",  
38 - "/v1/app/cooperation-projects/person/search": "",  
39 - }  
40 - var err error  
41 - if filterUrl, err := url.Parse(ctx.Request.RequestURI); err == nil {  
42 - // 不需要验证的接口  
43 - if _, ok := filterMap[filterUrl.Path]; ok {  
44 - next(ctx)  
45 - return  
46 - }  
47 - } else {  
48 - log.Logger.Error("parse url error:" + err.Error())  
49 - }  
50 - defer func() {  
51 - if err != nil {  
52 - ctx.Output.SetStatus(http.StatusOK)  
53 - ctx.Output.JSON(map[string]interface{}{  
54 - "msg": domain.ParseCodeMsg(domain.InvalidAccessToken),  
55 - "code": domain.InvalidAccessToken,  
56 - "data": struct{}{},  
57 - }, false, false)  
58 - }  
59 - }()  
60 -  
61 - tk := &domain.LoginToken{}  
62 - err = tk.ParseToken(tokenStr)  
63 - if err != nil {  
64 - log.Logger.Error(err.Error())  
65 - return  
66 - }  
67 - platform := domain.ParsePlatform(ctx.Input.Header("x-mmm-devicetype"))  
68 - // redis缓存  
69 - tokenCache := cache.LoginTokenCache{}  
70 - token, err := tokenCache.GetAccessToken(tk.Account, platform)  
71 - if err != nil {  
72 - log.Logger.Error(err.Error())  
73 - return  
74 - }  
75 - if token != tokenStr {  
76 - log1.Println("token not equal \n" + tk.Account + "\n" + tokenStr + "\n" + token)  
77 - err = fmt.Errorf("access token not exists")  
78 - return  
79 - }  
80 - ctx.Input.SetData(CtxKeyLoginToken{}, tk)  
81 - next(ctx)  
82 - }  
83 -}  
84 -  
85 -func NewCtxLoginToken(ctx *context.Context, tk domain.LoginToken) {  
86 - ctx.Input.SetData(CtxKeyLoginToken{}, domain.LoginToken{})  
87 -}  
88 -  
89 func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) { 15 func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) {
90 val := ctx.Input.GetData(CtxKeyLoginToken{}) 16 val := ctx.Input.GetData(CtxKeyLoginToken{})
91 if v, ok := val.(domain.LoginToken); ok { 17 if v, ok := val.(domain.LoginToken); ok {
@@ -94,7 +20,7 @@ func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) { @@ -94,7 +20,7 @@ func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) {
94 return domain.LoginToken{}, false 20 return domain.LoginToken{}, false
95 } 21 }
96 22
97 -func CheckAccessToken2() web.FilterFunc { 23 +func CheckAccessToken() web.FilterFunc {
98 return func(ctx *context.Context) { 24 return func(ctx *context.Context) {
99 tokenStr := ctx.Input.Header("x-mmm-accesstoken") 25 tokenStr := ctx.Input.Header("x-mmm-accesstoken")
100 filterMap := map[string]string{ 26 filterMap := map[string]string{
  1 +package middleware
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "github.com/beego/beego/v2/client/httplib"
  7 + "github.com/beego/beego/v2/server/web"
  8 + "github.com/beego/beego/v2/server/web/context"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
  10 + "io/ioutil"
  11 + "net/http"
  12 + "strings"
  13 +)
  14 +
  15 +type internalService interface {
  16 + GetResponseData(result service_gateway.GatewayResponse, data interface{}) error
  17 + CreateRequest(url string, method string) *httplib.BeegoHTTPRequest
  18 + BaseUrl() string
  19 +}
  20 +
  21 +func RedirectInternalService(prefix string, svr internalService) web.FilterFunc {
  22 + return func(ctx *context.Context) {
  23 + if !strings.HasPrefix(ctx.Request.RequestURI, prefix) {
  24 + return
  25 + }
  26 + var err error
  27 + var byteResult []byte
  28 + var data = make(map[string]interface{})
  29 + defer func() {
  30 + if err != nil {
  31 + ctx.Output.SetStatus(http.StatusOK)
  32 + ctx.Output.JSON(map[string]interface{}{
  33 + "msg": err.Error(),
  34 + "code": 1,
  35 + "data": struct{}{},
  36 + }, false, false)
  37 + } else {
  38 + ctx.Output.SetStatus(http.StatusOK)
  39 + ctx.Output.JSON(map[string]interface{}{
  40 + "msg": "成功",
  41 + "code": 0,
  42 + "data": data,
  43 + }, false, false)
  44 + }
  45 + }()
  46 +
  47 + method := strings.ToLower(ctx.Request.Method)
  48 + url := strings.Replace(ctx.Request.RequestURI, prefix, "", 1)
  49 + req := svr.CreateRequest(svr.BaseUrl()+url, method)
  50 + req.Body(ctx.Input.RequestBody)
  51 + response, err := req.Response()
  52 + if err != nil {
  53 + return
  54 + }
  55 + if response.StatusCode != http.StatusOK {
  56 + err = fmt.Errorf("%v", response.Status)
  57 + return
  58 + }
  59 +
  60 + byteResult, err = ioutil.ReadAll(response.Body)
  61 + if err != nil {
  62 + return
  63 + }
  64 + defer response.Body.Close()
  65 +
  66 + var result service_gateway.GatewayResponse
  67 + err = json.Unmarshal(byteResult, &result)
  68 + if err != nil {
  69 + return
  70 + }
  71 +
  72 + err = svr.GetResponseData(result, &data)
  73 + }
  74 +}
@@ -6,12 +6,26 @@ import ( @@ -6,12 +6,26 @@ import (
6 ) 6 )
7 7
8 func init() { 8 func init() {
  9 + // dictionary
  10 + web.Router("/v1/background/dictionary/", &backgroud_client.DictionaryController{}, "Post:CreateDictionary")
  11 + web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Put:UpdateDictionary")
  12 + web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Get:GetDictionary")
  13 + web.Router("/v1/background/dictionary/search", &backgroud_client.DictionaryController{}, "Post:ListDictionary")
  14 + web.Router("/v1/background/dictionary/remove", &backgroud_client.DictionaryController{}, "Post:RemoveDictionary")
  15 +
  16 + // menu
9 web.Router("/v1/background/menus/", &backgroud_client.MenuController{}, "Post:CreateMenu") 17 web.Router("/v1/background/menus/", &backgroud_client.MenuController{}, "Post:CreateMenu")
10 web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Put:UpdateMenu") 18 web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Put:UpdateMenu")
11 web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Get:GetMenu") 19 web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Get:GetMenu")
12 - //web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Delete:RemoveMenu")  
13 - //web.Router("/v1/background/menus/search", &backgroud_client.MenuController{}, "Get:ListMenu")  
14 web.Router("/v1/background/menus/search", &backgroud_client.MenuController{}, "Post:SearchMenu") 20 web.Router("/v1/background/menus/search", &backgroud_client.MenuController{}, "Post:SearchMenu")
15 web.Router("/v1/background/menus/batch-delete", &backgroud_client.MenuController{}, "Post:BatchDeleteMenu") 21 web.Router("/v1/background/menus/batch-delete", &backgroud_client.MenuController{}, "Post:BatchDeleteMenu")
16 web.Router("/v1/background/menus/batch-enable", &backgroud_client.MenuController{}, "Post:BatchEnableMenu") 22 web.Router("/v1/background/menus/batch-enable", &backgroud_client.MenuController{}, "Post:BatchEnableMenu")
  23 +
  24 + // company
  25 + //web.Router("/v1/background/company/", &backgroud_client.CompanyController{}, "Post:CreateCompany")
  26 + web.Router("/v1/background/company/:companyId", &backgroud_client.CompanyController{}, "Put:UpdateCompany")
  27 + web.Router("/v1/background/company/:companyId", &backgroud_client.CompanyController{}, "Get:GetCompany")
  28 + web.Router("/v1/background/company/search", &backgroud_client.CompanyController{}, "Post:SearchCompany")
  29 + web.Router("/v1/background/company/:companyId/audit", &backgroud_client.CompanyController{}, "Post:AuditCompany")
  30 + web.Router("/v1/background/company/:companyId/enable", &backgroud_client.CompanyController{}, "Post:EnableCompany")
17 } 31 }
1 -package routers  
2 -  
3 -import (  
4 - "github.com/beego/beego/v2/server/web"  
5 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/backgroud_client"  
6 -)  
7 -  
8 -func init() {  
9 - web.Router("/v1/background/dictionary/", &backgroud_client.DictionaryController{}, "Post:CreateDictionary")  
10 - web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Put:UpdateDictionary")  
11 - web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Get:GetDictionary")  
12 - web.Router("/v1/background/dictionary/search", &backgroud_client.DictionaryController{}, "Post:ListDictionary")  
13 - web.Router("/v1/background/dictionary/remove", &backgroud_client.DictionaryController{}, "Post:RemoveDictionary")  
14 -}