作者 yangfu

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

正在显示 28 个修改的文件 包含 928 行增加108 行删除
... ... @@ -7,6 +7,7 @@ require (
github.com/beego/beego/v2 v2.0.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/disintegration/imaging v1.6.2
github.com/emirpasic/gods v1.12.0
github.com/forgoer/openssl v0.0.0-20210828150411-6c5378b5b719
github.com/go-pg/pg/v10 v10.10.1
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
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/emicklei/proto v1.9.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"reflect"
"strings"
... ... @@ -23,6 +24,15 @@ type CompanySignUpCommand struct {
Password string `cname:"密码" json:"password" valid:"Required"`
// 短信验证码
SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"`
// 法人
LegalPerson string `cname:"法人" json:"legalPerson" valid:"Required"`
// 社会信用代码
SocialCreditCode string `cname:"社会信用代码" json:"socialCreditCode" valid:"Required"`
// 营业执照所在地
BusinessLicenseAddress domain.BusinessLicenseAddress `cname:"营业执照所在地" json:"businessLicenseAddress" valid:"Required"`
// 营业执照-附件
BusinessLicenseAttachments []domain.Attachment `cname:"营业执照-附件" json:"businessLicenseAttachments" valid:"Required"`
}
func (companySignUpCommand *CompanySignUpCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -406,6 +406,11 @@ func (svr AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUp
Contacts: companySignUpCommand.Contacts,
IndustryCategory: companySignUpCommand.IndustryCategory,
Scale: companySignUpCommand.Scale,
LegalPerson: companySignUpCommand.LegalPerson,
SocialCreditCode: companySignUpCommand.SocialCreditCode,
BusinessLicenseAttachments: companySignUpCommand.BusinessLicenseAttachments,
BusinessLicenseAddress: companySignUpCommand.BusinessLicenseAddress,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ... @@ -629,7 +634,7 @@ func (svr AuthService) matchUser(loginToken *domain.LoginToken) (*allied_creatio
loopUser1:
for _, v := range userSearchResult.Users {
for _, vv := range v.UserOrg {
if vv.OrgID == int(loginToken.OrgId) {
if vv.OrgID == int(loginToken.OrgId) && v.Company.Status == domain.CompanyAuthenticated {
currentOrgIsOK = true
currentUser = v
break loopUser1
... ... @@ -713,6 +718,9 @@ func (svr AuthService) GetCompanyOrgsByUser(queryParam *query.GetCompanyOrgsByUs
CompanyId: user.Company.CompanyId,
CompanyName: user.Company.CompanyName,
})
if user.Company.Status != domain.CompanyAuthenticated {
continue
}
}
for j := range user.UserOrg {
org := user.UserOrg[j]
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type AuditCompanyCommand struct {
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"`
// 审核状态
Status int `cname:"审核状态" json:"status" valid:"Required"`
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
}
func (updateCompanyCommand *AuditCompanyCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCompanyCommand *AuditCompanyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCompanyCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCompanyCommand).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
// type CreateCompanyCommand struct {
// // 企业名称
// CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"`
// // 规模
// Scale string `cname:"规模" json:"scale" valid:"Required"`
// // 公司Logo地址
// Logo string `cname:"公司Logo地址" json:"logo" valid:"Required"`
// // 公司地址
// Address string `cname:"公司地址" json:"address" valid:"Required"`
// // 所属行业
// IndustryCategory string `cname:"所属行业" json:"industryCategory" valid:"Required"`
// // 联系人
// Contacts string `cname:"联系人" json:"contacts" valid:"Required"`
// // 注册时间
// RegisteredTime time.Time `cname:"注册时间" json:"registeredTime,omitempty"`
// // 注册状态 1:已注册 2:待认证 3:已认证
// Status int `cname:"注册状态 1:已注册 2:待认证 3:已认证" json:"status,omitempty"`
// }
// func (createCompanyCommand *CreateCompanyCommand) Valid(validation *validation.Validation) {
// }
// func (createCompanyCommand *CreateCompanyCommand) ValidateCommand() error {
// valid := validation.Validation{}
// b, err := valid.Valid(createCompanyCommand)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(createCompanyCommand).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 EnableCompanyCommand struct {
// 企业id
CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"`
// 审核状态
Status int `cname:"审核状态" json:"status" valid:"Required"`
}
func (updateCompanyCommand *EnableCompanyCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCompanyCommand *EnableCompanyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCompanyCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCompanyCommand).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
// type ListCompanyCustomizeMenusCommand struct {
// // 企业id
// CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
// // 菜单类别 web app
// MenuCategory string `cname:"菜单类别" json:"menuCategory,omitempty" valid:"Required"`
// }
// func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
// }
// func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) ValidateCommand() error {
// valid := validation.Validation{}
// b, err := valid.Valid(listCompanyCustomizeMenusCommand)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(listCompanyCustomizeMenusCommand).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
// type RemoveCompanyCommand struct {
// // 企业id
// CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"`
// }
// func (removeCompanyCommand *RemoveCompanyCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
// }
// func (removeCompanyCommand *RemoveCompanyCommand) ValidateCommand() error {
// valid := validation.Validation{}
// b, err := valid.Valid(removeCompanyCommand)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(removeCompanyCommand).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-gateway/pkg/domain"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type UpdateCompanyCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 企业名称
CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"`
// 公司地址
Address string `cname:"公司地址" json:"address" valid:"Required"`
// 系统名称
SystemName string `cname:"系统名称" json:"systemName" valid:"Required"`
// 公司Logo地址
Logo string `cname:"公司Logo地址" json:"logo" valid:"Required"`
}
func (updateCompanyCommand *UpdateCompanyCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCompanyCommand *UpdateCompanyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCompanyCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateCompanyCommand).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
// type UpdateCompanyCustomizeMenusCommand struct {
// // 企业id
// CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"`
// // 菜单编号
// MenuId int64 `cname:"菜单编号" json:"menuId" valid:"Required"`
// // 菜单名称
// //MenuName string `cname:"菜单名称" json:"menuName" valid:"Required"`
// // 菜单别名
// MenuAlias string `cname:"菜单别名" json:"menuAlias" valid:"Required"`
// // 排序
// Sort int `cname:"排序" json:"sort" valid:"Required"`
// }
// func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) {
// //validation.SetError("CustomValid", "未实现的自定义认证")
// }
// func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) ValidateCommand() error {
// valid := validation.Validation{}
// b, err := valid.Valid(updateCompanyCustomizeMenusCommand)
// if err != nil {
// return err
// }
// if !b {
// elem := reflect.TypeOf(updateCompanyCustomizeMenusCommand).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 dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
type CompanyGetItemDto struct {
CompanyListItemDto
Remark string `json:"remark"`
// 法律相关
// 法人
LegalPerson string `json:"legalPerson"`
// 社会信用代码
SocialCreditCode string `json:"socialCreditCode"`
// 营业执照所在地
BusinessLicenseAddress interface{} `json:"businessLicenseAddress"`
// 营业执照-附件
BusinessLicenseAttachments []domain.Attachment `json:"businessLicenseAttachments"`
}
func (dto *CompanyGetItemDto) LoadDto(c allied_creation_user.CompanyItem, u allied_creation_user.UserDetail) {
companyListItemDto := &CompanyListItemDto{}
companyListItemDto.LoadDto(c, u)
dto.CompanyListItemDto = *companyListItemDto
dto.Remark = c.CompanyInfo.Remark
dto.LegalPerson = c.CompanyInfo.Legal.LegalPerson
dto.SocialCreditCode = c.CompanyInfo.Legal.SocialCreditCode
dto.BusinessLicenseAddress = c.CompanyInfo.Legal.BusinessLicenseAddress
dto.BusinessLicenseAttachments = c.CompanyInfo.Legal.BusinessLicenseAttachments
}
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
type CompanyListItemDto struct {
// 企业id
CompanyId int `json:"companyId"`
// 公司名称
CompanyName string `json:"companyName"`
// 规模
Scale string `json:"scale,omitempty"`
// 所属行业
IndustryCategory string `json:"industryCategory,omitempty"`
// 联系人
Contacts string `cname:"联系人" json:"contacts"`
// 手机号码
Phone string `cname:"手机号码" json:"phone"`
// 注册时间
RegisteredTime string `json:"registeredTime,omitempty"`
// 公司状态 1:已注册(待审核) 2:已通过 3:已拒绝
Status int `json:"status"`
}
func (dto *CompanyListItemDto) LoadDto(c allied_creation_user.CompanyItem, u allied_creation_user.UserDetail) *CompanyListItemDto {
dto.CompanyId = c.CompanyId
dto.CompanyName = c.CompanyInfo.CompanyName
dto.Scale = c.CompanyInfo.Scale
dto.IndustryCategory = c.CompanyInfo.IndustryCategory
dto.Contacts = u.UserInfo.UserName
dto.Phone = u.UserInfo.Phone
dto.RegisteredTime = c.CompanyInfo.RegisteredTime.Format("2006-01-02")
dto.Status = c.Status
return dto
}
type CompanyListItemsDto []*CompanyListItemDto
func (dto *CompanyListItemsDto) LoadDto(items []allied_creation_user.CompanyItem, users []allied_creation_user.UserDetail) {
var mapItems = make(map[int]allied_creation_user.CompanyItem)
for i := range items {
mapItems[items[i].CompanyId] = items[i]
}
for i := range users {
if v, ok := mapItems[users[i].Company.CompanyId]; ok {
company := &CompanyListItemDto{}
*dto = append(*dto, company.LoadDto(v, users[i]))
}
}
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetCompanyQuery struct {
// 企业id
CompanyId int `cname:"企业id" json:"companyId" valid:"Required"`
}
func (getCompanyQuery *GetCompanyQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCompanyQuery *GetCompanyQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCompanyQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getCompanyQuery).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"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type ListCompanyQuery struct {
// 查询偏离量
PageNumber int `json:"pageNumber"`
// 查询限制
PageSize int `json:"pageSize" valid:"Required"`
// 状态
Status int `cname:"状态" json:"status,omitempty"`
// 企业名称
CompanyName string `cname:"企业名称" json:"companyName,omitempty"`
}
func (listCompanyQuery *ListCompanyQuery) Valid(validation *validation.Validation) {
}
func (listCompanyQuery *ListCompanyQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCompanyQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listCompanyQuery).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 (
"github.com/emirpasic/gods/sets/hashset"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
// 企业
type CompanyService struct {
}
// 创建企业
// func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) {
// return nil, nil
// }
// 返回企业
func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompanyQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
result, err := creationUserGateway.CompanyGet(allied_creation_user.ReqCompanyGet{
CompanyId: getCompanyQuery.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
userResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
InCompanyIds: []interface{}{result.CompanyId},
UserType: domain.UserTypeCompanyAdmin,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var user allied_creation_user.UserDetail
if len(userResult.Users) > 0 {
user = userResult.Users[0]
}
companyDto := &dto.CompanyGetItemDto{}
companyDto.LoadDto(allied_creation_user.CompanyItem(*result), user)
return companyDto, nil
}
func (companyService *CompanyService) AuditCompany(cmd *command.AuditCompanyCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
_, err := creationUserGateway.AuditCompany(allied_creation_user.ReqCompanyAudit{
CompanyId: int(cmd.CompanyId),
Status: cmd.Status,
Remark: cmd.Remark,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return struct{}{}, nil
}
func (companyService *CompanyService) EnableCompany(cmd *command.EnableCompanyCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
_, err := creationUserGateway.EnableCompany(allied_creation_user.ReqCompanyEnable{
CompanyId: int(cmd.CompanyId),
Status: cmd.Status,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return struct{}{}, nil
}
// 返回企业列表
func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
result, err := creationUserGateway.CompanySearch(allied_creation_user.ReqCompanySearch{
Offset: (listCompanyQuery.PageNumber - 1) * listCompanyQuery.PageSize,
Limit: listCompanyQuery.PageSize,
Status: listCompanyQuery.Status,
CompanyName: listCompanyQuery.CompanyName,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
companySet := hashset.New()
for i := range result.Companys {
companySet.Add(result.Companys[i].CompanyId)
}
var users = make([]allied_creation_user.UserDetail, 0)
if companySet.Size() > 0 {
userResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
InCompanyIds: companySet.Values(),
UserType: domain.UserTypeCompanyAdmin,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
users = userResult.Users
}
companyListItemsDto := dto.CompanyListItemsDto{}
companyListItemsDto.LoadDto(result.Companys, users)
return 0, companyListItemsDto, nil
}
// 返回自定义菜单列表(匹配有设置的菜单)
// func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand *command.ListCompanyCustomizeMenusCommand) (interface{}, error) {
// return nil, nil
// }
// 移除企业
// func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) {
// return nil, nil
// }
// 更新企业
func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *command.UpdateCompanyCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(updateCompanyCommand.Operator)
_, err := creationUserGateway.CompanyUpdate(allied_creation_user.ReqCompanyUpdate{
CompanyId: updateCompanyCommand.Operator.CompanyId,
CompanyName: updateCompanyCommand.CompanyName,
Address: updateCompanyCommand.Address,
SystemName: updateCompanyCommand.SystemName,
Logo: updateCompanyCommand.Logo,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return updateCompanyCommand, nil
}
func NewCompanyService(options map[string]interface{}) *CompanyService {
newCompanyService := &CompanyService{}
return newCompanyService
}
... ...
package domain
// 公司状态状态 1:已注册 2:已通过 3:已拒绝
const (
CompanyRegistered = iota + 1
CompanyAuthenticated
CompanyUnauthenticated
)
//公司
type CompanyData struct {
CompanyID int `json:"companyId"`
... ... @@ -12,3 +19,10 @@ type Company struct {
Logo string `json:"logo"`
CompanyName string `json:"companyName"`
}
// 营业执照所在地
type BusinessLicenseAddress struct {
Province string `json:"province"`
City string `json:"city"`
Address string `json:"address"`
}
... ...
... ... @@ -28,3 +28,7 @@ func NewHttplibAlliedCreationUser(operator domain.Operator) *HttplibAlliedCreati
}
}
func (gateway HttplibAlliedCreationUser) BaseUrl() string {
return gateway.baseUrL
}
... ...
... ... @@ -135,7 +135,7 @@ func (gateway HttplibAlliedCreationUser) CompanyRemove(param ReqCompanyRemove) (
// CompanyGet 返回企业
func (gateway HttplibAlliedCreationUser) CompanyGet(param ReqCompanyGet) (*DataCompanyGet, error) {
url := gateway.baseUrL + "/company/{companyId}"
url := gateway.baseUrL + "/company/" + strconv.Itoa(param.CompanyId)
method := "GET"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:返回企业。", map[string]interface{}{
... ... @@ -164,6 +164,66 @@ func (gateway HttplibAlliedCreationUser) CompanyGet(param ReqCompanyGet) (*DataC
return &data, err
}
func (gateway HttplibAlliedCreationUser) AuditCompany(param ReqCompanyAudit) (DataCompanyAudit, error) {
url := gateway.baseUrL + fmt.Sprintf("/company/%d/audit", param.CompanyId)
method := "post"
req := gateway.CreateRequest(url, method)
moduleDesc := "审核公司"
//TODO traceID
log.Logger.Debug("向用户模块请求数据:"+moduleDesc, map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
}
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析错误:%w", err)
}
var data DataCompanyAudit
err = gateway.GetResponseData(result, &data)
return data, err
}
func (gateway HttplibAlliedCreationUser) EnableCompany(param ReqCompanyEnable) (DataCompanyEnable, error) {
url := gateway.baseUrL + fmt.Sprintf("/company/%d/enable", param.CompanyId)
method := "post"
req := gateway.CreateRequest(url, method)
moduleDesc := "启用公司"
//TODO traceID
log.Logger.Debug("向用户模块请求数据:"+moduleDesc, map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
}
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析错误:%w", err)
}
var data DataCompanyEnable
err = gateway.GetResponseData(result, &data)
return data, err
}
// CompanySearch 返回企业列表
func (gateway HttplibAlliedCreationUser) CompanySearch(param ReqCompanySearch) (*DataCompanySearch, error) {
url := gateway.baseUrL + "/company/search"
... ...
package allied_creation_user
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
//企业注册
type (
ReqAuthCompanySignUp struct {
... ... @@ -9,6 +11,15 @@ type (
Password string `json:"password"`
Phone string `json:"phone"`
Scale string `json:"scale"`
// 法人
LegalPerson string `cname:"法人" json:"legalPerson" valid:"Required"`
// 社会信用代码
SocialCreditCode string `cname:"社会信用代码" json:"socialCreditCode" valid:"Required"`
// 营业执照所在地
BusinessLicenseAddress domain.BusinessLicenseAddress `cname:"营业执照所在地" json:"businessLicenseAddress" valid:"Required"`
// 营业执照-附件
BusinessLicenseAttachments []domain.Attachment `cname:"营业执照-附件" json:"businessLicenseAttachments" valid:"Required"`
}
DataAuthCompanySignUp struct {
... ...
package allied_creation_user
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"time"
)
//创建企业
type (
ReqCompanyCreate struct {
... ... @@ -49,18 +54,78 @@ type (
//返回企业
type (
ReqCompanyGet struct {
CompanyId int `json:"companyId"`
}
DataCompanyGet struct {
DataCompanyGet CompanyItem
)
type (
ReqCompanyAudit struct {
CompanyId int `json:"-"`
// 审核状态
Status int `cname:"审核状态" json:"status" valid:"Required"`
// 备注
Remark string `cname:"备注" json:"remark" valid:"Required"`
}
DataCompanyAudit map[string]interface{}
)
type (
ReqCompanyEnable struct {
CompanyId int `json:"-"`
// 审核状态
Status int `cname:"审核状态" json:"status" valid:"Required"`
}
DataCompanyEnable map[string]interface{}
)
//返回企业列表
type (
ReqCompanySearch struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset,omitempty"`
// 查询限制
Limit int `cname:"查询限制" json:"limit,omitempty"`
// 状态
Status int `cname:"状态" json:"status,omitempty"`
// 企业名称
CompanyName string `cname:"企业名称" json:"companyName,omitempty"`
}
DataCompanySearch struct {
Companys []CompanyItem `json:"companys"`
Count int `json:"count"`
}
CompanyItem struct {
CompanyId int `json:"companyId"`
CompanyConfig struct {
SystemName string `json:"systemName"`
Theme string `json:"theme"`
} `json:"companyConfig"`
CompanyInfo struct {
CompanyName string `json:"companyName"`
Scale string `json:"scale"`
IndustryCategory string `json:"industryCategory"`
RegisteredTime time.Time `json:"registeredTime"`
Legal struct {
LegalPerson string `json:"legalPerson"`
SocialCreditCode string `json:"socialCreditCode"`
BusinessLicenseAddress struct {
Province string `json:"province"`
City string `json:"city"`
Address string `json:"address"`
} `json:"businessLicenseAddress"`
BusinessLicenseAttachments []domain.Attachment `json:"businessLicenseAttachments"`
} `json:"legal"`
Remark string `json:"备注"`
} `json:"companyInfo"`
Status int `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
)
... ...
... ... @@ -106,6 +106,8 @@ type (
EnableStatus int `cname:"状态(1:启用 2:禁用 3:注销)" json:"enableStatus,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
InEnableStatus []int `cname:"状态(1:启用 2:禁用 3:注销)" json:"inEnableStatus,omitempty"`
// 匹配多个公司
InCompanyIds []interface{} `json:"inCompanyIds,omitempty"`
// 自定义高级查询
AdvancedQuery string `json:"advancedQuery"`
... ...
package beego
import (
"encoding/json"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
"net/http"
"os"
"strconv"
... ... @@ -48,25 +49,24 @@ func init() {
filters.SecureKeyMap["token"] = "x-mmm-accesstoken"
web.InsertFilter("/*", web.BeforeRouter, AllowCors())
web.InsertFilter("/*", web.BeforeRouter, filters.CreateRequstLogFilter(log.Logger))
web.InsertFilter("/v1/web/*", web.BeforeExec, middleware.CheckAccessToken2())
web.InsertFilter("/v1/app/*", web.BeforeExec, middleware.CheckAccessToken2())
web.InsertFilter("/v1/user/*", web.BeforeExec, middleware.CheckAccessToken2())
web.InsertFilter("/v1/web/*", web.BeforeExec, middleware.CheckAccessToken())
web.InsertFilter("/v1/app/*", web.BeforeExec, middleware.CheckAccessToken())
web.InsertFilter("/v1/user/*", web.BeforeExec, middleware.CheckAccessToken())
web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(log.Logger), web.WithReturnOnOutput(false))
web.InsertFilter("/v1/app11/*", web.BeforeExec, filters.SecureHandler(
filters.WithEnableCheckTimestamp(false),
filters.WithOnInvalidRequest(func(ctx *context.Context) {
headerData, _ := json.Marshal(ctx.Input.Context.Request.Header)
log.Logger.Info("签名验证失败:" + string(headerData))
}),
))
//web.InsertFilterChain("/v1/*", middleware.CheckAccessToken)
//web.InsertFilter("/v1/app11/*", web.BeforeExec, filters.SecureHandler(
// filters.WithEnableCheckTimestamp(false),
// filters.WithOnInvalidRequest(func(ctx *context.Context) {
// headerData, _ := json.Marshal(ctx.Input.Context.Request.Header)
// log.Logger.Info("签名验证失败:" + string(headerData))
// }),
//))
web.InsertFilter("/v1/common/user/area/*", web.BeforeRouter, middleware.RedirectInternalService("/v1/common/user", allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})))
}
func AllowCors() func(ctx *context.Context) {
return func(ctx *context.Context) {
ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH")
//ctx.Output.Header("Access-Control-Max-Age", "3600")
//ctx.Output.Header("Access-Control-Allow-Headers", "*,x-mmm-version")
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,*")
ctx.Output.Header("Access-Control-Allow-Credentials", "true")
ctx.Output.Header("Access-Control-Allow-Origin", "*") //origin
... ...
package backgroud_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/service"
)
type CompanyController struct {
baseController
}
// func (controller *CompanyController) CreateCompany() {
// companyService := service.NewCompanyService(nil)
// createCompanyCommand := &command.CreateCompanyCommand{}
// controller.Unmarshal(createCompanyCommand)
// data, err := companyService.CreateCompany(createCompanyCommand)
// controller.Response(data, err)
// }
func (controller *CompanyController) UpdateCompany() {
companyService := service.NewCompanyService(nil)
updateCompanyCommand := &command.UpdateCompanyCommand{}
controller.Unmarshal(updateCompanyCommand)
updateCompanyCommand.Operator = controller.GetOperator()
data, err := companyService.UpdateCompany(updateCompanyCommand)
controller.Response(data, err)
}
func (controller *CompanyController) GetCompany() {
companyService := service.NewCompanyService(nil)
getCompanyQuery := &query.GetCompanyQuery{}
companyId, _ := controller.GetInt(":companyId")
getCompanyQuery.CompanyId = companyId
data, err := companyService.GetCompany(getCompanyQuery)
controller.Response(data, err)
}
// func (controller *CompanyController) RemoveCompany() {
// companyService := service.NewCompanyService(nil)
// removeCompanyCommand := &command.RemoveCompanyCommand{}
// controller.Unmarshal(removeCompanyCommand)
// companyId, _ := controller.GetInt64(":companyId")
// removeCompanyCommand.CompanyId = companyId
// data, err := companyService.RemoveCompany(removeCompanyCommand)
// controller.Response(data, err)
// }
func (controller *CompanyController) SearchCompany() {
companyService := service.NewCompanyService(nil)
listCompanyQuery := &query.ListCompanyQuery{}
controller.Unmarshal(listCompanyQuery)
cnt, data, err := companyService.ListCompany(listCompanyQuery)
controller.returnPageListData(cnt, data, err, listCompanyQuery.PageNumber)
}
func (controller *CompanyController) AuditCompany() {
companyService := service.NewCompanyService(nil)
cmd := &command.AuditCompanyCommand{}
controller.Unmarshal(cmd)
companyId, _ := controller.GetInt64(":companyId")
cmd.CompanyId = companyId
data, err := companyService.AuditCompany(cmd)
controller.Response(data, err)
}
func (controller *CompanyController) EnableCompany() {
companyService := service.NewCompanyService(nil)
cmd := &command.EnableCompanyCommand{}
controller.Unmarshal(cmd)
companyId, _ := controller.GetInt64(":companyId")
cmd.CompanyId = companyId
data, err := companyService.EnableCompany(cmd)
controller.Response(data, err)
}
... ...
package middleware
import (
"fmt"
log1 "log"
"net/http"
"net/url"
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
type CtxKeyLoginToken struct{}
func JWTAuth(ctx *context.Context) {
}
func CheckAccessToken(next web.FilterFunc) web.FilterFunc {
return func(ctx *context.Context) {
tokenStr := ctx.Input.Header("x-mmm-accesstoken")
filterMap := map[string]string{
"/v1/auth/login/pwd": "",
"/v1/auth/login/sms": "",
"/v1/auth/login/qrcode": "",
"/v1/auth/org-switch": "",
"/v1/user/company-orgs": "",
"/v1/auth/captcha-init": "",
"/v1/auth/qrcode-init": "",
"/v1/auth/sms-code": "",
"/v1/auth/check-sms-code": "",
"/v1/auth/company-sign-up": "",
"/v1/auth/reset-password": "",
"/v1/auth/refresh-token": "",
"/v1/app/cooperation-projects/person/search": "",
}
var err error
if filterUrl, err := url.Parse(ctx.Request.RequestURI); err == nil {
// 不需要验证的接口
if _, ok := filterMap[filterUrl.Path]; ok {
next(ctx)
return
}
} else {
log.Logger.Error("parse url error:" + err.Error())
}
defer func() {
if err != nil {
ctx.Output.SetStatus(http.StatusOK)
ctx.Output.JSON(map[string]interface{}{
"msg": domain.ParseCodeMsg(domain.InvalidAccessToken),
"code": domain.InvalidAccessToken,
"data": struct{}{},
}, false, false)
}
}()
tk := &domain.LoginToken{}
err = tk.ParseToken(tokenStr)
if err != nil {
log.Logger.Error(err.Error())
return
}
platform := domain.ParsePlatform(ctx.Input.Header("x-mmm-devicetype"))
// redis缓存
tokenCache := cache.LoginTokenCache{}
token, err := tokenCache.GetAccessToken(tk.Account, platform)
if err != nil {
log.Logger.Error(err.Error())
return
}
if token != tokenStr {
log1.Println("token not equal \n" + tk.Account + "\n" + tokenStr + "\n" + token)
err = fmt.Errorf("access token not exists")
return
}
ctx.Input.SetData(CtxKeyLoginToken{}, tk)
next(ctx)
}
}
func NewCtxLoginToken(ctx *context.Context, tk domain.LoginToken) {
ctx.Input.SetData(CtxKeyLoginToken{}, domain.LoginToken{})
}
func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) {
val := ctx.Input.GetData(CtxKeyLoginToken{})
if v, ok := val.(domain.LoginToken); ok {
... ... @@ -94,7 +20,7 @@ func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) {
return domain.LoginToken{}, false
}
func CheckAccessToken2() web.FilterFunc {
func CheckAccessToken() web.FilterFunc {
return func(ctx *context.Context) {
tokenStr := ctx.Input.Header("x-mmm-accesstoken")
filterMap := map[string]string{
... ...
package middleware
import (
"encoding/json"
"fmt"
"github.com/beego/beego/v2/client/httplib"
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"io/ioutil"
"net/http"
"strings"
)
type internalService interface {
GetResponseData(result service_gateway.GatewayResponse, data interface{}) error
CreateRequest(url string, method string) *httplib.BeegoHTTPRequest
BaseUrl() string
}
func RedirectInternalService(prefix string, svr internalService) web.FilterFunc {
return func(ctx *context.Context) {
if !strings.HasPrefix(ctx.Request.RequestURI, prefix) {
return
}
var err error
var byteResult []byte
var data = make(map[string]interface{})
defer func() {
if err != nil {
ctx.Output.SetStatus(http.StatusOK)
ctx.Output.JSON(map[string]interface{}{
"msg": err.Error(),
"code": 1,
"data": struct{}{},
}, false, false)
} else {
ctx.Output.SetStatus(http.StatusOK)
ctx.Output.JSON(map[string]interface{}{
"msg": "成功",
"code": 0,
"data": data,
}, false, false)
}
}()
method := strings.ToLower(ctx.Request.Method)
url := strings.Replace(ctx.Request.RequestURI, prefix, "", 1)
req := svr.CreateRequest(svr.BaseUrl()+url, method)
req.Body(ctx.Input.RequestBody)
response, err := req.Response()
if err != nil {
return
}
if response.StatusCode != http.StatusOK {
err = fmt.Errorf("%v", response.Status)
return
}
byteResult, err = ioutil.ReadAll(response.Body)
if err != nil {
return
}
defer response.Body.Close()
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return
}
err = svr.GetResponseData(result, &data)
}
}
... ...
... ... @@ -6,12 +6,26 @@ import (
)
func init() {
// dictionary
web.Router("/v1/background/dictionary/", &backgroud_client.DictionaryController{}, "Post:CreateDictionary")
web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Put:UpdateDictionary")
web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Get:GetDictionary")
web.Router("/v1/background/dictionary/search", &backgroud_client.DictionaryController{}, "Post:ListDictionary")
web.Router("/v1/background/dictionary/remove", &backgroud_client.DictionaryController{}, "Post:RemoveDictionary")
// menu
web.Router("/v1/background/menus/", &backgroud_client.MenuController{}, "Post:CreateMenu")
web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Put:UpdateMenu")
web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Get:GetMenu")
//web.Router("/v1/background/menus/:menuId", &backgroud_client.MenuController{}, "Delete:RemoveMenu")
//web.Router("/v1/background/menus/search", &backgroud_client.MenuController{}, "Get:ListMenu")
web.Router("/v1/background/menus/search", &backgroud_client.MenuController{}, "Post:SearchMenu")
web.Router("/v1/background/menus/batch-delete", &backgroud_client.MenuController{}, "Post:BatchDeleteMenu")
web.Router("/v1/background/menus/batch-enable", &backgroud_client.MenuController{}, "Post:BatchEnableMenu")
// company
//web.Router("/v1/background/company/", &backgroud_client.CompanyController{}, "Post:CreateCompany")
web.Router("/v1/background/company/:companyId", &backgroud_client.CompanyController{}, "Put:UpdateCompany")
web.Router("/v1/background/company/:companyId", &backgroud_client.CompanyController{}, "Get:GetCompany")
web.Router("/v1/background/company/search", &backgroud_client.CompanyController{}, "Post:SearchCompany")
web.Router("/v1/background/company/:companyId/audit", &backgroud_client.CompanyController{}, "Post:AuditCompany")
web.Router("/v1/background/company/:companyId/enable", &backgroud_client.CompanyController{}, "Post:EnableCompany")
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/backgroud_client"
)
func init() {
web.Router("/v1/background/dictionary/", &backgroud_client.DictionaryController{}, "Post:CreateDictionary")
web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Put:UpdateDictionary")
web.Router("/v1/background/dictionary/:dictionaryId", &backgroud_client.DictionaryController{}, "Get:GetDictionary")
web.Router("/v1/background/dictionary/search", &backgroud_client.DictionaryController{}, "Post:ListDictionary")
web.Router("/v1/background/dictionary/remove", &backgroud_client.DictionaryController{}, "Post:RemoveDictionary")
}